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
Related
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.
Manifest:
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed : Attribute permission#<YOUR PACKAGE>.permission.C2D_MESSAGE#name value=(.permission.C2D_MESSAGE) from AndroidManifest.xml
This error generate on Android Studio to build a project.
How to solve this error?
The problem is (as the error message shows) the same permission is available in another manifest (firebase manifest). So you can remove it from your manifest to solve the problem (easy approach). You can also override it in your manifest like below:
<permission android:name="<your-package-name>.permission.C2D_MESSAGE"
android:protectionLevel="signature"
tools:replace="android:name"/>
For using tools you need to add the xmlns:tools="http://schemas.android.com/tools" line in the manifest tag as below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:allowBackup="false"
android:label="#string/app_name"/>
You can just write below code in your AndroidManifest.xml.
<manifest ...
xmlns:tools="http://schemas.android.com/tools"
...>
And in the application tag ->
<application
...
tools:replace="android:name">
I added PAYTM SDK in my project and now I am facing a problem with merging manifest file since the library has its own manifest file.
So I am getting
> Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application#icon value=(#mipmap/logo) from AndroidManifest.xml:19:9-42
is also present at [com.paytm.pgsdk:pgsdk:1.0.6] AndroidManifest.xml:12:9-45 value=(#drawable/ic_launcher).
Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:16:5-178:19 to override.
But after adding tools:replace="android:icon" in my application tag, my app has crashed at runtime by the following exception.
Caused by: java.lang.IllegalStateException: You need to use a
Theme.AppCompat theme (or descendant) with this activity.
Here is my manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.demo">
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
tools:replace="android:icon"
android:icon="#mipmap/login_logo"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
.
.
.
</application>
Just remove icon="#mipmap/login_logo" and theme="#style/AppTheme" from your Application Manifest and replace drawable ic_launcher in PayTM SDK with your app logo and that would do it.
Application will merge both manifests and you will get your desired theme and logo will be fetched from PayTM's manifest hence you would have replaced their ic_launcher with yours.
Finally, I have solved that theme issue by removing conflicting AppTheme's style from SDK.
part of my AndroidManifest.xml
<application
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppThemeCompat"
android:largeHeap="true" >
I'm newbie in android developer, i use eclipse mars with sdk 25.1.3 and i get this error. they are no '/xml' folder under 'res/' in my project.
what should i do to fix this issue?
sorry for my english.
Does your manifest tag look like this?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.my.appexample">
I never used "fullBackupContent" but every attribute needs to be declared with the xmlns to use it.
Also, if you say you are new to android development. Why do you need "fullBackupContent" and "largeHeap"? Did you copy that from somewhere or is it on purpose?
i have 2 versions of AndroidManifest.xml files in my project, one is the main and another for debug.
in both of them i have android:label and in the debug version i have tools:replace="label"
after adding a library through gradle i suddenly see:
Error:Execution failed for task ':app:processMobileDebugManifest'.
Manifest merger failed : Attribute application#label value=(XXXX Debug) from AndroidManifest.xml:36:13-45
is also present at [library_name] AndroidManifest.xml:13:9-41 value=(#string/app_name).
Suggestion: add 'tools:replace="android:label"' to element at AndroidManifest.xml:7:5-20:19 to override.
it already exists there! what am i doing wrong?
Edit1:
main xml:
<application
android:name="[package_name]"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
debug xml:
<application
tools:replace="name, label"
android:name="[package_name]"
android:label="[debug_name]">
third party library xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
I found out that the label should have the same value like all others.
Meaning that tools:replace works only if all labels looks like this:
android:label="#string/app_name"
In my case it didn't work because in the debug manifest it looked like this:
android:label="debug name"
But once i changed it to android:label="#string/app_name" and added string in the debug/values dir it started working correctly.
Seems like a bug in Android Studio.