17

I am using the new gradle android buildsystem.

The project consists of two android library projects and one main project.

Using the ant build, the manifest merger must be enable in project.properties. But when using the gradle build system the manifest merger is enabled by default. How can i disable the manifest merger?

endian
  • 4,761
  • 7
  • 32
  • 54
  • I'd be interested to know why you want to disable it? We are not planning to enable it (at this time) but we want to support all use cases. – Xavier Ducrohet Dec 19 '12 at 18:53
  • @Xav: We built our project till now with ant and didn't take any care of the AndroidManifest.xml in our library projects. So we had little problems migrating to gradle because of manifest merger errors. – endian Dec 20 '12 at 08:17
  • 1
    @Xav: I'm also wishing I could disable merging. The manifest merging appears to be giving priority to the manifest in main. I have values, i.e. "icon" in my flavor that needs to override main, but the merger is throwing away those values. – Douglas Ferguson Mar 11 '13 at 08:47
  • 1
    @DouglasFerguson you mean the android:icon attribute? Why do you just override the icon itself in the resource folder of the flavor? – Xavier Ducrohet Mar 13 '13 at 00:06
  • @XavierDucrohet I've suffered the same thing, but I just need to have an extra attribute being the android:sharedUserId in the android manifest's manifest element in the release product flavor. How can I do that? – Kevin Tan Jan 10 '14 at 11:12

5 Answers5

10

Edit: this is actually possible though indirectly, starting with 0.3

What you need to do is disable the processManifest task so that it doesn't run and tell the processResources where the manifest to use is:

android.applicationVariants.all { variant ->
    variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
    variant.processManifest.enabled=false
}

Note that if you are customizing the app package name through the DSL, you should keep the default manifest untouched in the default location to provide a consistent package name for the R classes, and then have your manually merged manifests somewhere else and point each variant processResources task to them.

Xavier Ducrohet
  • 28,383
  • 5
  • 88
  • 64
  • 3
    I'm getting "Could not find property 'buildVariants' on com.android.build.gradle.AppExtension_Decorated@57eaaca" when I try this. – Dylan Aug 26 '13 at 00:36
  • 3
    +1 this is no longer valid for 0.5+ plugin, and documentation doesn't help understand how to exclude some library's manifest. – Oleksii Malovanyi Sep 22 '13 at 17:03
8

This may help.

 android.applicationVariants.all{ variant ->
       variant.outputs.each { output ->
         output.processResources.manifestFile = file('AndroidManifest.xml')
         output.processManifest.enabled=false
       }
  }
5

For the 0.6.+ plugin you also have to change from buildVariants to applicationVariants:

android.applicationVariants.all { variant ->
    variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
    variant.processManifest.enabled=false
}
urish
  • 8,943
  • 8
  • 54
  • 75
3

It doesn't look like these solutions work for the 1.0 plugin:

Could not find property 'processResources' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@774f1d0b.

Anyone have an update? Our issue is a stray activity showing up in the final apk from recyclerview-v7:21.0.3:

<activity
   android:label="RecyclerViewTestActivity"
   android:name="android.support.v7.widget.TestActivity"/>

Update: It looks like manifest merging can be configured (see http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger ). In this specific case, the TestActivity coming from the recyclerview-v7 library can be removed with:

<activity
    android:name="android.support.v7.widget.TestActivity"
    android:label="RecyclerViewTestActivity"
    tools:node="remove"/>

Thanks Filip.

Community
  • 1
  • 1
mttmllns
  • 1,740
  • 1
  • 15
  • 13
  • Problem with my app is that the generated apk has Read_Contacts permission in it however i am not declaring it in the manifest. Not sure how to resolve this problem. – Shajeel Afzal Nov 01 '15 at 16:51
  • @ShajeelAfzal check `build/outputs/logs/manifest-merger-debug-report.txt` to see where each bit in `build/intermediates/manifests/full/debug/AndroidManifest.xml` came from. (May not be available or be in different files in older versions; I'm using 2.0.0.) – TWiStErRob Jul 22 '16 at 22:28
2

For the 0.5.+ plugin you have to change from each to all like this:

android.buildVariants.all { variant ->
    variant.processResources.manifestFile = file('src/main/AndroidManifest.xml')
    variant.processManifest.enabled=false
}
pearcoding
  • 1,149
  • 1
  • 9
  • 28
jqyao
  • 170
  • 6