3
votes

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?

3

3 Answers

1
votes

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.

0
votes

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

0
votes

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>