Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android build will not merge manifests from libraries

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?

like image 458
TacB0sS Avatar asked Mar 26 '17 13:03

TacB0sS


People also ask

How do I merge manifest files on Android?

If you want to apply the merge rule markers to only a specific imported library, add the tools:selector attribute with the library package name. For example, with the following manifest, the remove merge rule is applied only when the lower-priority manifest file is from the com. example. lib1 library.

What is manifest placeholder?

Android Manifest usually contains pre-defined or static information which is then used to run the app. However, Android toolchain provides customization by allowing you to specify dynamic information through variable declaration, generally referred as Android Manifest placeholders.

What does AndroidManifest XML do?

The AndroidManifest. xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc.


1 Answers

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.

like image 172
Maher Abuthraa Avatar answered Oct 03 '22 22:10

Maher Abuthraa