14

We have multiple projects, depending on a many Android lib modules. To avoid duplicated xml tags in the apps manifests, we put the relevant receivers, services and activities in their respective modules.

Till today, we used:

  • Android Studio: 2.2.1
  • gradle: 2.1.3
  • buildToolsVersion: 23.0.3

Today we've updated to:

  • Android Studio: 2.3
  • gradle: 2.3.0
  • buildToolsVersion: 25.0.0

Up until this update, everything worked just fine and the manifests were merged, we had conflicts and we fixed them. As of the update we've done, the manifests will not merge, at all!!

--- Update 1 ---

We've used the Merged Manifest view, and saw that it just doesn't include the manifests in the merge, the only thing it does merge from the modules manifest is the permissions, so for example, if I add a new permission to a modules manifest it would ONLY merge it and not the rest of the elements!

Nothing to merge

I guarantee there are a lot of stuff to merge!

--- Update 2 ---

It seems that everything outside the application tag it merges into the main manifest, and everything within the application tag, it doesn't.

--- Update 3 ---

Module that doesn't merge:

Gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            jniDebuggable true
        }
    }
}

dependencies {
    compile project(path: ':android-infra')
    compile 'com.google.android.gms:play-services-gcm:9.0.0'
    compile project(path: ':engine-core-server')
    compile project(path: ':engine-core-aneeda')
}

Manifest:

<manifest package="com.sensiya.voip.managers.gcm"
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="com.google.android.c2dm.permission.KAKI"/>


    <application
        tools:node="replace">
        <service
            android:enabled="true"
          android:name="com.sensiya.voip.managers.gcm.GcmIntentService"/>

        <receiver          android:name="com.sensiya.voip.managers.gcm.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>

                <category android:name="com.iamplus.onenumber.device"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>

Module that will merge:

Gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            jniDebuggable true
        }
    }
}

dependencies {
    compile project(path: ':android-infra')
    compile 'com.sensiya:sense-services-client:1.24.2@aar'
    compile project(path: ':engine-core-server')
    compile project(path: ':engine-core-aneeda')
}

Manifest:

<manifest package="com.iamplus.android.senseServices"
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools">

    <application
        tools:node="replace">
        <service
            android:name="com.iamplus.senseServices.ContextualEventService"
            android:enabled="true"/>

        <service
            android:name="com.iamplus.senseServices.Serv"
            android:enabled="true"/>

        <service
            android:name="com.iamplus.senseServices.Serv1"
            android:enabled="true"/>
    </application>    
</manifest>

Any suggestions?

TacB0sS
  • 10,106
  • 12
  • 75
  • 118
  • 1
    No logs in console? No errors? – azizbekian Mar 26 '17 at 16:43
  • Asolutly nothing... – TacB0sS Mar 26 '17 at 16:51
  • can you share your app gradle file. – Jigar Patel Mar 29 '17 at 06:55
  • not really it has a few dependencies files, anything specific I can provide? – TacB0sS Mar 29 '17 at 06:57
  • Did you try doing a Gradle Clean and an android studio 'invalidate caches and restart'. If there was a previous conflict it could just be a caching issue – Nick Cardoso Mar 29 '17 at 11:00
  • Yes cleaned, deleted build folder from all the modules... – TacB0sS Mar 29 '17 at 11:09
  • It would be helpful if you just share bare project with no production code. – azizbekian Mar 29 '17 at 14:04
  • @TacB0sS check if your minSdkVersion and targetSdkVersion in AndroidManifest.xml will be overridden by what you have mention in your build.gradle files....to me this happens usually with update sometimes...so you simply make changes their after that clean ,rebuild,sync... – PN10 Mar 29 '17 at 14:49
  • _will not merge_ like there is an error; or like there is no error and no result either? – tynn Apr 02 '17 at 08:20
  • Can you try to create new project with same package name and move your files to the new project and also use recent build tool version 25.3.1, Android studio 2.3 has some bugs – MathankumarK Apr 03 '17 at 12:28
  • @tynn There are no errors, and it just complete the "merge" process without merging any of the dependencies components into the final manifest – TacB0sS Apr 03 '17 at 18:45
  • @TacB0sS, so you expect to see lets say activities elements from ModuleA's manifest merged to your app's manifest ? and its missing there .. right ? – Maher Abuthraa Apr 05 '17 at 09:34
  • Yes, and they are not there. .. – TacB0sS Apr 05 '17 at 09:55
  • See my updated answer. I think your issue is with importing modules or its component not with merging. can you check if you can assess any resource in modules ? – Maher Abuthraa Apr 05 '17 at 10:16
  • It woild compile the project if it wouldn't... i can access strings and classes from all the unmeged modules – TacB0sS Apr 05 '17 at 10:17

6 Answers6

9

It could be many things.Since you didn't provide code, I will guess you are using default merge behavior. For more information, see: Merge conflict heuristics

You can use Merged Manifest view to preview the results of your merged manifest and find conflict errors.

In general, merge by default should work. Then just use Merged Manifest view to see how & where you lost values during merging. Using Merge rule markers would help you to manage merge by assigning rules markers.

If there is no merge at all. so it's probably a dependency issue between modules.

Note that dependency order plays a crucial role with modules which have the same priority level, such as libraries.

--- Update 5.April.2017 ---

Here are some useful tips:

  1. Try to update and rebuild other libs as much as you can.
  2. Remove all dependencies and then clean project, then add them again. and check if you import them properly. that could be done by build the project without issues.
  3. Note that since gradle 2.2.0 assets from modules won't be accessible in app.
  4. Check you manifest if merge process is not disabled exciplicitly by attribute: tools:node=”remove" or tools:node="removeAll" or in gradle( see this Disable Manifest Merger in Android Gradle Build)
  5. Try to create a demo with a module and track merging. and then match outputs to your projects. This will make it clear that is not configuration issue but Android Studio 2.3 ( so then re-install fresh version )

--- Update(2) 5.April.2017 ---

After you had added code, I could see that you are using Attribute

tools:node="replace"

Under application element in your modules (and probably in app's manifest too). I think that is the reason why you didn't get any manifest merged from imported modules merged to your app's manifest. See tools:node="replace" under Node markers.

Replace the lower-priority element completely. That is, if there is a matching element in the lower-priority manifest, ignore it and use this element exactly as it appears in this manifest.

That means both modules above will never get any thing merged with manifest from:

  • android-infra
  • com.sensiya:sense-services-client:1.24.2
  • engine-core-server
  • engine-core-aneeda

So get rid of that attribute and clean and rebuild modules. then rebuild whole project.

Community
  • 1
  • 1
Maher Abuthraa
  • 17,493
  • 11
  • 81
  • 103
  • This seems like the best way so far.. I was not aware of the Merged View... I'll check it soon and post back – TacB0sS Apr 03 '17 at 18:43
  • 1. tried, nothing. 2. tried, nothing. 3. known. 4. doesn't exits. 5. this is not related to the studio version, this also happens when building from the command line from other computers using gradle... so??? – TacB0sS Apr 05 '17 at 10:32
  • the replace was added in attempt to fix the issue, it is irrelevant as one module with replace does merge and another doesn't. we tried creating another project showing the issue, we could not reproduce it. we tried removing all the flags from the application tag in all submodules, we could not get it to merge... there is a bug hidden deep in the Android plugin, and we just can't place it – TacB0sS Apr 05 '17 at 21:48
  • Thanks for the [link](https://developer.android.com/studio/build/manifest-merge.html#inspect_the_merged_manifest_and_find_conflicts). In my case AS showed AndroidManifest in merged view, but two bottom tabs (`Text` and `Merged Manifest`) disappeared. I reopened AS, it showed AndroidManifest in normal view. – CoolMind Mar 23 '21 at 14:43
2

If you are getting manifest merge conflicts you have two options.

1) find all the manifest files included in your project including the ones in libraries that you have as dependencies, and ensure there are no conflicting configurations.

or 2) add some merge resolution rules to your Manifests to dictate how each conflict should be resolved.

There is a great page on that here with many details.
https://developer.android.com/studio/build/manifest-merge.html

Stephen
  • 4,041
  • 22
  • 39
  • there are no conflicting, there are no gardle console error or warning messages, and only if I copy the components manually into the app manifest it actually adds them to the final manifest – TacB0sS Apr 03 '17 at 18:42
0

From Android Studio

Build ---> Clean project
then
Build --> Make Project
This should help fix

0

I had a similar problem for Unity. I was able to solve it by going on the SDK Manager and removing the latest android api. Then I installed a slightly older api and it worked (API 21 or 22 I think)

What the SDK Manager looks like

nreh
  • 476
  • 8
  • 13
0

I recently have same problem in my production code. Having one libraries into app module exists also in other Gradle Dependency causes the duplicate entries. We need to exclude such module or libraries from conflicted one.

For that we must know number of libraries used by a particular Gadle dependency.

Consider a case where I using "bolts-android-1.2.0.jar" in my app gradle. In same gradle I m using facebookSDK as below.

compile('com.facebook.android:facebook-android-sdk:4.5.0')

So I have to exclude "bolts-android" as below

compile('com.facebook.android:facebook-android-sdk:4.5.0') {
        exclude module: 'bolts-android'
    }

So how to know that facebookSDK uses "bolts-android"

Here you can use plugin Android Method Count

Tarun Dholakiya
  • 829
  • 1
  • 10
  • 16
0

Seems like the problem is from using tools:node="replace" in the application element. From the documentation:

...if there is a matching element in the lower-priority manifest, ignore it and use this element exactly as it appears in this manifest.

What you actually want to use is tools:node="merge" which is the default behavior.

Merge all attributes in this tag and all nested elements when there are no conflicts using the merge conflict heuristics. This is the default behavior for elements.

guy.gc
  • 3,359
  • 2
  • 24
  • 39