Gradle merge wrapper/sub-module's Android manifest into a main module's manifest

后端 未结 3 1440
梦谈多话
梦谈多话 2020-12-22 06:49

I have the following modules inside my project for which I cannot get Gradle to merge the Android manifests properly:

myproject_alpha
myproject_beta
myprojec         


        
相关标签:
3条回答
  • 2020-12-22 06:58

    Declare the header of your manifest as follows:

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

    Then, use one of the following appropriate attributes on any activity, activity-alias, service, receiver, or provider element that you want to merge:

    tools:merge="override"
    tools:merge="remove"
    

    This info was gleaned from:
    https://android.googlesource.com/platform/tools/base/+/idea133/build-system/manifest-merger/src/main/java/com/android/manifmerger/ManifestMerger.java

    0 讨论(0)
  • 2020-12-22 07:12

    If you examine the class that merges the manifests, you'll see that the mergeNewOrEqual() method is not smart enough to merge elements that are not identical. Unfortunately, this is the method that is used to merge providers and activities.

    So the only "solution" would be to either to only define the elements in one place, or to give them identical signatures in both definitions.

    0 讨论(0)
  • 2020-12-22 07:16

    I have issues with the answer above in that when I compile, I always get the message

    Invalid instruction 'merge', valid instructions are : REMOVE,REPLACE,STRICT

    I found success in importing the tools as in @swooby answer and then adding tools:node="merge" in the <activity> tag for the Activity being launched I want to replace and then adding

    <intent-filter tools:node="remove">
                    <action android:name="android.intent.action.MAIN"/>
    

    to the Activity's launcher that I do not want to have a launcher icon

    Hope this helps.

    0 讨论(0)
提交回复
热议问题