Disable Manifest Merger in Android Gradle Build

泪湿孤枕 提交于 2019-11-26 14:07:46

问题


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?


回答1:


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.




回答2:


This may help.

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



回答3:


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
}



回答4:


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.




回答5:


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
}


来源:https://stackoverflow.com/questions/13937123/disable-manifest-merger-in-android-gradle-build

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