Manifest merger failed versionCode is also present at - android

I have a complex AndroidManifest.xml, which contains a receiver:
<receiver android:name=com.my.package.ApplicationBroadcastReceiver>
I want to create an AndroidManifest.xml for the debug version of my app.
I placed that under debug/AndroidManifest.xml. The only difference in the debug manifest is that I am using another receiver:
<receiver android:name=com.my.package.DebugApplicationBroadcastReceiver>
For now, I copied AndroidManifest.xml into debug/AndroidManifest.xml and just changed that line. After reading this page about merge rules, I specified this rule at the top of my debug/AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.my.package"
android:versionCode="1"
android:versionName="1.0"
tools:node="replace">
However, when building I am getting this error:
Manifest merger failed : Attribute manifest#versionCode value=(1) from AndroidManifest.xml:5
is also present at AndroidManifest.xml:5
Attributes of <manifest> elements are not merged.
So even though I specified tools:node="replace" in the manifest tag, merging still fails.
My question has two parts:
A.How can I make the merging work?
B.Since the difference between AndroidManifest.xml and debug/AndroidManifest.xml is just one line, how can I just specify the line that is overriden instead of copying the whole file?

Based on your error message, you need something like this:
tools:replace="android:versionCode"

Related

Crashlytics Manifest Merge issue with Instant App Architecture

I have a multi-feature instant app setup and when I try to view the merged manifest of the application I see the following:
Error: Attribute provider#com.crashlytics.android.CrashlyticsInitProvider#authorities
value=(com.happyapp.app.crashlyticsinitprovider) from AndroidManifest.xml:14:13-75 is also present
at AndroidManifest.xml:40:87-161 value=(com.happyapp.app.app.crashlyticsinitprovider). Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:12:9-16:39 to override. app main manifest (this file), line 13
I have looked multiple places and have not found any way to fix this. I can follow the suggestion, but the line that is mentioned to fix doesn't exist in the manifest.
This is the installed app manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.happyapp.app" />
My colleague was able to workaround the issue by adding the following element to the installed apk AndroidManifest.xml
<application>
<provider
android:name="com.crashlytics.android.CrashlyticsInitProvider"
android:authorities="com.happy.happyapp.happyapp.crashlyticsinitprovider"
tools:replace="android:authorities" />
</application>

How to deal with "${applicationid}" in Xamarin?

I'm trying to create bindings for Zendesk library and I faced with a problem.
Zendesk Belvedere library (belvedere-1.0.2.1.aar) contains a file provider in its manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
...
<application>
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:authorities="${applicationId}.belvedere.attachments"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/belvedere_attachment_storage" />
</provider>
</application>
</manifest>
When Gradle is used as build tool, it puts this aar to the APK file and it replaces ${applicationId}.belvedere.attachments with com.your_package_name_here.belvedere.attachments in the merged manifest file. It's fine.
However, Xamarin handles it differently. Here is what I found in the manifest of my final APK:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
...
<application
...
...
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:exported="false"
android:authorities="dollar_openBracket_applicationId_closeBracket"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/belvedere_attachment_storage" />
</provider>
...
...
</application>
</manifest>
Obviously, dollar_openBracket_applicationId_closeBracket is not what I need.
Seems everything works, however it makes impossible to install several Xamarin applications that use these bindings, because all of them would have conflicting providers with the same authority (and user would get INSTALL_FAILED_CONFLICTING_PROVIDER error).
Is there a way to change dollar_openBracket_applicationId_closeBracket in the manifest?
Edit: A small sample that shows the problem: https://gitlab.com/lassana/ZendeskXamarin/
The current Xamarin.Android manifest merge build task, up to and including
version 7.1.0.19, does not provide any bundeID/ApplicationID (${}} substitution in the merged manifest like gradle does.
This is just a limitation in the manifest processing/merge task, thus you are ending up with dollar_openBracket_applicationId_closeBracket in your final manifest and will have to correct both manifests yourself.
The only current solution know to me to avoid the manifest merge task and it's limitation is to:
Remove the file provider entry from the '.aar`'s manifest
Add the complete file provider entry your app's manifest
Note: You have to do both steps
Depending upon how often the .aar is changing and where you are sourcing the .aar file from:
Manually unzip the aar, remove the entry and re-zip the aar (the quickest way)
Automated this in a build step via a shell script using bash or powershell cmds
Write a MSBuild C#-based Task to do it.
Request that the aar manifest be changed upstream (not likely to happen ;-) since it works fine w/ gradle)
FYI: Personally I have seen the ${applicationId} issue you are having a few times. I have written build scripts (bash/.ps1) to do the manifest fix-up as it seems to always be some special case in the .arr's manifest that I am dealing with.
According to Microsoft team, Xamarin.Build.Download (0.4.12-preview) finally fixes this bug.
So, you should follow these steps:
Update the Nuget Package to 0.4.12-preview3
Restart the IDE
Delete all cached locations of NuGet Packages
Delete bin/obj
Rebuild
The main manifest file of your project is the higher priority manifest, so if you add the provider element to main manifest file and apply a merge rule marker for android:authorities attribute, the merger tools replaces the android:authorities value that you declare in the main manifest.
Declare provider element in main manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
...
...
<application>
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:authorities="com.example.belvedere.attachments"
tools:replace=”android:authorities” >
</provider>
</application>

androidTest AndroidManifest.xml ignored

I have the same issue mentioned in this post AndroidTest Manifest permission not detected
and this post AndroidManifest in androidTest directory being ignored
--> If I put the test manifest in androidTest, debugAndroidTest, androidTestDebug, it never gets picked up and merged.
the answers about putting the AndroidManifest.xml in the debug folder are correct; that does seem to work. (put the test manifest in src/debug
What I want to know is why can't you put it in the androidTest directory? All the documentation I've read while trying to figure this out makes it sound like you should be able to, and that if you can't then I'm thinking that sounds like some bug in the manifest merger.
For what it's worth, I'm using Android Studio
That is correct and totally agree with you on the confusing documentation. The AndroidManifest.xml under androidTest* source sets would be packaged for the instrumentation APK that does your tests on your actual app APK. If you open the generated APKs for debug and androidTest under build/outputs/apk/ after compiling your app module with the command gradlew assembleDebugAndroidTest (assuming that you haven't changed the testBuildType in you build.gradle, more info here), you'll find that any AndroidManifest.xml configuration added under androidTest will be in the androidTest APK and not in your debug app APK.
And also as you said, in case you need test specific configurations like extra permissions, you'll have to place them in the AndroidManifest.xml under the debug source set instead of main, hence they'll only be available for testing your app but not in your release build. Of course you can always double check by opening the generated APKs after compiling to make sure that the configuration is right for each build variant.
If you need to add extra permissions for tests, you can do it.
You should set the same android:sharedUserId in default AndroidManifest.xml and androidTest/AndroidManifest.xml.
For example:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:sharedUserId="com.yourpackagename.uid">
<application
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:allowBackup">
</application>
</manifest>
androidTest/AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="com.yourpackagename.uid">
<uses-permission android:name="android.permission.***" />
</manifest>
For details: https://stackoverflow.com/a/14196493/3901000

Tools: replace not replacing in Android manifest

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

Manifest merger failed when trying to add my own logo to android app - Android Studio

I tried to add my own icon to my app in Android Studio and I encountered a Manifest merger fail. I fount an identical question here but his answer is not working for me. I tried adding tools:replace="android:icon" and tools:replace="android:icon,android:theme" (on 2 separate occasions of course) but no change.
This is the error Android Studio is keep giving me.
Error:(12, 9) Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application#icon value=(#drawable/footynews_logo_new) from AndroidManifest.xml:12:9
is also present at com.arasthel:gnavdrawer-library:1.1.4:4:45 value=(#drawable/ic_launcher)
Suggestion: add 'tools:replace="android:icon"' to <application> element at AndroidManifest.xml:9:5 to override
Error:(12, 9) Attribute application#icon value=(#drawable/footynews_logo_new) from AndroidManifest.xml:12:9
EDIT : I just found out even though I thought the app was using the ic_launcher in my project directory, it is actually using the ic_launcher in one of the libraries I'm using. How do I force the app to use my launcher icon instead?
tools:replace="android:icon,android:theme"
should work. Hope you added
xmlns:tools="http://schemas.android.com/tools"
If this is not working you have another option. Use the old manifest merger. Add this in your build.gradle file
android { useOldManifestMerger true }
You can find more information here.
Add two line in manifest file :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..."
xmlns:tools="http://schemas.android.com/tools"> <!--Add this line-->
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
tools:replace="icon, label"/> <!--Add this line-->
</manifest>

Categories

Resources