Manifest Merger Error when using Dynamic Features and Build Flavors

自作多情 提交于 2021-02-09 10:13:58

问题


With dynamic-feature-modules it is possible to define in the AndroidManifest.xml wheter a module should come preinstalled:

<dist:module
    ...
    dist:onDemand="false"
    dist:title="@string/title_shop">
    ....
</dist:module>

or not:

<dist:module
    ...
    dist:onDemand="true"
    dist:title="@string/title_shop">
    ....
</dist:module>

I have two build flavors in my project. The module should be preinstalled in one flavor but not in the other.

The idea is to have this default AndroidManifest.xml in the main source set:

<dist:module
    ...
    dist:onDemand="true"
    dist:title="@string/title_shop">
    ....
</dist:module>

For build flavors that should have the module preinstalled - I create a AndroidManifest.xml file that overrides that dist:onDemand property to false:

<dist:module
    ...
    tools:replace="dist:onDemand"
    dist:onDemand="false"
    ...
</dist:module>

Unfortunately, this does not work. The Manifest Merger fails with the following errors:

Merging Errors: Error: tools:replace specified at line:11 for attribute dist:onDemand, but no new value specified shop manifest, line 10 Error: Validation failed, exiting shop manifest.

Does anyone have an idea what's wrong here?


回答1:


This answer worked for me. The idea is to have two copies of the AndroidManifest.xml, which are identical except

<dist:module
    ...
    tools:node="replace"
    dist:onDemand="false">
    ...
</dist:module>

which replaces the whole element.




回答2:


The manifest merger tool combines all XML elements from each file by following some merge heuristics. If the merger tool finds that both manifests contain the same attribute with different values, then a merge conflict occurs.

Docs: https://developer.android.com/studio/build/manifest-merge




回答3:


To expand on celaeno's answer

If I tried to have just debug and release (or whatever your two build types are) AndroidManifests that were full and exact copies except changes to dist:onDemand line. This didnt' work. Gradle yelled at me about a missing src/main/AndroidManifest.xml. So I actually created three files:

  1. main
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    package="com.example.somefeature">

    <application ...>
        <activity
            android:name=...
        </activity>
    </application>
 <!-- NO dist:module block -->
</manifest>
  1. debug

    <dist:module
        dist:instant="false"
        dist:title="@string/somefeature">
        <dist:delivery>
            <dist:install-time />
        </dist:delivery>
        <dist:fusing dist:include="true" />
    </dist:module>
    

  2. release

    <dist:module
        dist:instant="false"
        dist:title="@string/somefeature">
        <dist:delivery>
            <dist:on-demand />
        </dist:delivery>
        <dist:fusing dist:include="true" />
    </dist:module>
    



来源:https://stackoverflow.com/questions/56951262/manifest-merger-error-when-using-dynamic-features-and-build-flavors

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