androidandroid-manifestandroid-module

ERROR: Attribute application@name is too present


Hello I am developing 2 modules A and B and B depends of A.

The last two have a Application class, for get the context staticaly.

And in the two modules have them manifest.

Module A manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="apps.com.a">

    <application android:name=".AA"/>

</manifest>

Module B manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="apps.com.b">

    <application
        android:name=".BApp">
    </application>

</manifest>

When I try execute the Junit, I get the following error:

Manifest merger failed : Attribute application@name value=(apps.b.BApp) from [__tested_artifact__::blibrary] AndroidManifest.xml:14:18-72
    is also present at [:alibrary] AndroidManifest.xml:11:18-78 value=(apps.com.a.AApplication).
    Suggestion: add 'tools:replace="android:name"' to <application> element at manifestMerger2718201306699938665.xml:7:5-9:19 to override.

Any idea of how solve this, i will put 'tools:replace="android:name"' is correct, or can be errors?


Solution

  • Yes you can use tools:replace="android:name" to solve this issue

    According to the docs

    Your APK file can contain just one AndroidManifest.xml file, but your Android Studio project may contain several—provided by the main source set, build variants, and imported libraries. So when building your app, the Gradle build merges all manifest files into a single manifest file that's packaged into your APK.

    The manifest merger tool combines all XML elements from each file by following some merge heuristics and by obeying merge preferences that you have defined with special XML attributes. This page describes how manifest merging works and how you can apply merge preferences to resolve merge conflicts.


    tools:replace="attr, ..."

    Replace the specified attributes in the lower-priority manifest with those from this manifest. In other words, always keep the higher-priority manifest's values.