Disable Manifest Merger in Android Gradle Build

旧巷老猫 提交于 2019-11-27 08:22:50

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.

This may help.

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

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
}
mttmllns

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.

jqyao

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
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!