I want to setup a script to change values and keys on android manifest during production build.
This is the manifest (removed unnecessary code for simplicity)
<?xml version="1.0"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.sample">
<application android:name=".MainApplication" android:label="#string/app_name" android:icon="#mipmap/ic_launcher" android:roundIcon="#mipmap/ic_launcher_round" android:allowBackup="false" android:theme="#style/AppTheme">
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Branch keys -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_test_ad82b98f289hfhfoBxfzSNXq"/>
</application>
</manifest>
I simply want to change the Branch key with the production one, eg: key_live_0932nfe9hfbf
I have tried this
xmlstarlet edit --inplace --update "/manifest/application/meta-data[#android:name='io.branch.sdk.BranchKey']/#android:value" --value "test" $thisDirectory/../android/app/src/main/res/values/strings.xml
and get this output
Undefined namespace prefix: /manifest/application/meta-data[#android:name='io.branch.sdk.BranchKey']/#android:value
Invalid expression: /manifest/application/meta-data[#android:name='io.branch.sdk.BranchKey']/#android:value
when I remove the latest part of xPath #android:value it works but nothing is changed (of course).
What I'm doing wrong? Thanks
I can't replicate your problem, for some reason, but this seems to be a namespace problem. Try changing your --update parameter to
-update "/manifest/application/meta-data[#android:name='io.branch.sdk.BranchKey']/#*[local-name()='value']"
and see if it works.
Related
I am working in Android 2.3.3, and have run into this error: "Tag manifest attribute package has invalid character'_'. Initially, I was getting this error because my package name contained an underscore (com.isco_pipe.www.fieldtechapp). I have since renamed the package and removed the underscore (as you can see in the manifest file below). But the error persists upon an attempt to rebuild. Any thoughts?
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iscopipe.www.fieldtechapp">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher"
android:label="#string/app_name" android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true" android:theme="#style/AppTheme">
<activity android:name="com.iscopipe.www.fieldtechapp.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Note: I previously asked a question about not being able to debug my app on my device (running Android Studio on a virtual machine). I am now attempting to setup and run my app in Android Studio directly on my Windows laptop to see if I can run the app on an emulator and debug from there. Unable to attach debugger to Android process in Android Studio 2.3.3
Check your build.gradle file also, what you gave in applicationId.
Make sure that you are editing the proper file. Android Studio has the absolutely aggravating "feature" where certain errors cause a file in build/ to pop up in the editor. In your case, it would be a merged manifest, not your actual manifest. Editing files in build/ will have no effect, as they get re-created on each build. So, make sure that you have modified your actual manifest (e.g., src/main/AndroidManifest.xml).
Ok so I was going through a tutorial online, then when i tried to change my build.gradle file to compileSdkVersion 21 instead of 23 everything lost the plot and now all my previous projects etc are all showing errors.
In the AndroidManifest.xml the 2 http lines and all the android: are all red and the the activity opening tag has a red squiggly line under it also. I have zero idea what i have done wrong! Almost like internet has gone? Just a noob so i have no idea please help!
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/tools"
package="com.site.project" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This answer extends #adelphus'.
A new app\build\intermediates\manifests\full\debug\AndroidManifest.xml would have listed these errors. Close and reopen the AndroidManifest.xml file from the project pane under app > manifests.
Hope this works for you.
You have duplicate schema definitions for the xmlns:android namespace in your manifest file - only one schema per namespace is allowed and I suspect the compiler is getting confused by the duplicate entry.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/tools"
package="com.site.project" >
should be:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.site.project" >
The namespace schema definitions are important - they are used to define attribute prefixes. Because your duplicate entry is invalidating the android namespace, all attributes prefixed with android: will be wrong - this is why all the android: attributes have an error (red line) displayed.
Alternatively, just remove the tools namespace completely if you're not using any attributes with the tools: prefix in your manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.site.project" >
you need download jdk here "https://www.oracle.com/technetwork/java/javase/downloads/index.html"
then go to File > Project Structure > here you config path jdk default C:\Program Files\Java\jdk-11.0.2 . Hope this works for you
I think you have two AndroidManifest.xml files to change it. Just rename the debug AndroidManifest.xml and that solution works for me.
Search for the AndroidManifest.xml file(s). on the project ParentPath. if there are multiple, keep one and delete the others.(usually find many other)
I am getting the error "Tag attribute package has invalid character ' '." in the Android Manifest, while there is no obviously invalid character. Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exampl e.harounsmida.test2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name="com.example.harounsmida.test2.app.AppController"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.harounsmida.test2.LoginActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.harounsmida.test2.RegisterActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" />
<activity
android:name="com.example.harounsmida.test2.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop" />
<activity
android:name="com.example.harounsmida.test2.UploadToServerActivity"
android:label="#string/app_name"
android:launchMode="singleTop" />
</application>
</manifest>
I don't understand where is the problem, Android Studio says that "File under the build folder are generated and should not be edited." although I didn't edit it.
Remove space from package name :
package="com.exampl e.harounsmida.test2"
After removing space :
package="com.example.harounsmida.test2"
For those who still can't solve this problem :
1 - Close Android Studio.
2 - Browse to your project directory.
3 - Rename the project directory name to something else.
4 - Open Android Studio and open your project (browse to the renamed directory) .
5 - Select Build --> Edit Flavors --> Type something like yourname.myapplication in application id textbox (avoid using non English characters or space)
Image
6 - Select Build --> Rebuild Project and you are good to go.
Please consider gradle file and see what you have given as applicationId, any name that you have given in applicationId will be copied from gradle file and pasted to manifest
Also see for space and extra character in package's value
Try this code
package="com.example.harounsmida.test2"
remove the space in your package definition because space is not allowed
After throwing the error as mentioned above, Android Studio opens the file "debug\AndroidManifest.xml". Note that the Manifest file for the project is "main\AndroidManifest.xml". I didn't notice initially and was removing the space from the former file (which Android Studio opens up).
Hope it helps!
I am using a gradle project with many different library dependencies and using the new manifest merger. In my <application /> tag I have it set up as such:
<application tools:replace="android:icon, android:label, android:theme, android:name"
android:name="com.example.myapp.MyApplcation"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/application_name"
android:logo="#drawable/logo_ab"
android:theme="#style/AppTheme"
>
....
</application>
Yet I am receiving the error:
/android/MyApp/app/src/main/AndroidManifest.xml:29:9 Error:
Attribute application#icon value=(#drawable/ic_launcher) from AndroidManifest.xml:29:9
is also present at {Library Name} value=(#drawable/app_icon)
Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:26:5 to override
/android/MyApp/app/src/main/AndroidManifest.xml:30:9 Error:
Attribute application#label value=(#string/application_name) from AndroidManifest.xml:30:9
is also present at {Library Name} value=(#string/app_name)
Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:26:5 to override
/android/MyApp/app/src/main/AndroidManifest.xml:27:9 Error:
Attribute application#name value=(com.example.myapp.MyApplication) from AndroidManifest.xml:27:9
is also present at {Another Library}
Suggestion: add 'tools:replace="android:name"' to <application> element at AndroidManifest.xml:26:5 to override
/android/MyApp/app/src/main/AndroidManifest.xml:32:9 Error:
Attribute application#theme value=(#style/AppTheme) from AndroidManifest.xml:32:9
is also present at {Library Name} value=(#style/AppTheme)
Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:26:5 to override
Declare your manifest header like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourpackage"
xmlns:tools="http://schemas.android.com/tools">
Then you can add to your application tag the following attribute:
<application
tools:replace="icon, label" ../>
For example I need to replace icon and label.
I fixed same issue. Solution for me:
add the xmlns:tools="http://schemas.android.com/tools" line in the manifest tag
add tools:replace=.. in the manifest tag
move android:label=... in the manifest tag
Example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:replace="allowBackup, label"
android:allowBackup="false"
android:label="#string/all_app_name"/>
Try reordering your dependencies in your gradle file. I had to move the offending library from the bottom of the list to the top, and then it worked.
I just experienced the same behavior of tools:replace=... as described by the OP.
It turned out that the root cause for tools:replace being ignored by the manifest merger is a bug described here. It basically means that if you have a library in your project that contains a manifest with an <application ...> node containing a tools:ignore=... attribute, it can happen that the tools:replace=... attribute in the manifest of your main module will be ignored.
The tricky point here is that it can happen, but does not have to. In my case I had two libraries, library A with the tools:ignore=... attribute, library B with the attributes to be replaced in the respective manifests and the tools:replace=... attribute in the manifest of the main module. If the manifest of B was merged into the main manifest before the manifest of A everything worked as expected. In opposite merge order the error appeared.
The order in which these merges happen seems to be somewhat random. In my case changing the order in the dependencies section of build.gradle had no effect but changing the name of the flavor did it.
So, the only reliable workaround seems to be to unpack the problem causing library, remove the tools:ignore=... tag (which should be no problem as it is a hint for lint only) and pack the library again.
And vote for the bug to be fixed, of cause.
Final Working Solution for me (Highlighted the tages in the sample code):
add the xmlns:tools line in the manifest tag
add tools:replace in the application tag
Example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pagination.yoga.com.tamiltv"
**xmlns:tools="http://schemas.android.com/tools"**
>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
**tools:replace="android:icon,android:theme"**
>
The missing piece for me was this:
xmlns:tools="http://schemas.android.com/tools"
for example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.your.appid">
You can replace those in your Manifest application tag:
<application
tools:replace="android:icon, android:label, android:theme, android:name,android:allowBackup"
android:allowBackup="false"...>
and will work for you.
The following hack works:
add the xmlns:tools="http://schemas.android.com/tools" line in the
manifest tag
add
tools:replace="android:icon,android:theme,android:allowBackup,label"
in the application tag
tools:replace="android:supportsRtl,android:allowBackup,icon,label">
FIXED IT
HAD THE EXACT ERROR, Just add this tools:replace="android:icon,android:theme"
into your application tag in your manifest,
it works just fine,
You can replace those in your Manifest application tag:
<application
...
tools:replace="android:label, android:icon, android:theme"/>
and will work for you.
Explanation
Using such a dependency/library in your gradle file which has those labels in its Manifest's application tag may produce this problem and replacing them in your Manifest is the solution.
My problem is multi modules project with base module, app module and feature module.
Each module has AndroidManifest of its own, and I implemented build variant for debug and main.
So we must sure that "android:name" just declared in Manifest of debug and main only, and do not set it in any of Manifest in child module.
Ex:
Manifest in main:
<application
android:name=".App"/>
Manifest in debug:
<application
tools:replace="android:name"
android:name=".DebugApp"
/>
Do not set "android:name" in other Manifest files like this:
<application android:name=".App">
Just define in feature module like this and it will merged fine
<application>
I also went through this problem and changed that:
<application android:debuggable="true" android:icon="#drawable/app_icon" android:label="#string/app_name" android:supportsRtl="true" android:allowBackup="false" android:fullBackupOnly="false" android:theme="#style/UnityThemeSelector">
to
<application tools:replace="android:allowBackup" android:debuggable="true" android:icon="#drawable/app_icon" android:label="#string/app_name" android:supportsRtl="true" android:allowBackup="false" android:fullBackupOnly="false" android:theme="#style/UnityThemeSelector">
I was receiving a similar error on a project I was importing:
Multiple entries with same key: android:icon=REPLACE and
tools:icon=REPLACE
Fixed after changing the below line within the application tag:
tools:replace="icon, label, theme"
to
tools:replace="android:icon, android:label, android:theme"
This is new androidManifest.xml for flutter
<application
android:label="Your app Name"
tools:replace="android:label"
android:name="io.flutter.app.FlutterApplication"
android:networkSecurityConfig="#xml/network_security_config"
android:usesCleartextTraffic="true"
android:icon="#mipmap/ic_launcher">
please make to add android:label in the first line in <application, 'cause if you are using this package flutter_app_name will throw an error if the not sorted like example Above
I keep getting an error that says, "Element type "application" must be followed by either attribute specifications, ">" or "/>"."
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thenewboston.sammy"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
I'm getting the error right below this:
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is the right form, see if you didn't close some tags.
<application android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
...>
<activity ...>
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
As my friend said , check the right format
For me It was like this :
BEFORE :
<activity android:name=".DisplayMessageActivity" android:label="display_message_activity"
</activity>
AFTER:
<activity android:name=".DisplayMessageActivity" android:label="display_message_activity" >
</activity>
Then the error disappeared
In my case, a comment had been placed (by the build tools?) inside the application tag:
<application android:allowBackup="true"
<!-- android:debuggable="true" -->
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme">
After I removed the entire debuggable=true comment line - everything worked.
I just ran into this error for a completely different reason. For some reason Android Studio had replaced every instance of the string name with "name" (e.g. it wrapped them all in double quotes) in my XML. It completely broke everything.
I had to clear out the double quotes from everything, clean the project and rebuild it.
If you're a flutter developer and you're getting this exception you must know there are two AndroidManifest file in your flutter project. One is inside debug folder and another one is main folder. My main folder AndroidManifest is ok and well formatted but AndroidManifest in debug folder is not ok and not well formatted due to a git conflict.
you must fix this.