Search code examples
androidandroid-manifestdynamic-feature-module

Android manifest merging fails for release builds after introducing dynamic feature module


When assembling a release build for my android project i am getting the following error:

> Task :app:processReleaseMainManifest
/Users/user/Repos/my-app/app/src/main/AndroidManifest.xml Error:
        Package name 'de.abc.someapp' used in: AndroidManifest.xml, :some_dynamic_feature.
/Users/user/Repos/my-app/app/src/release/AndroidManifest.xml Error:
        Validation failed, exiting

The module 'some_dynamic_feature' is a newly created module setup as a dynamic feature module.

This is its build.gradle

plugins {
  id 'com.android.dynamic-feature'
  id 'kotlin-android'
}

android {
  compileSdkVersion Versions.AndroidSdk.compile
  defaultConfig {
    minSdkVersion Versions.AndroidSdk.min
    targetSdkVersion Versions.AndroidSdk.target
  }
}

dependencies {
  implementation project(':app')
  implementation library_androidx_appcompat
  implementation library_androidx_activity
  implementation library_androidx_core
  implementation library_android_play_core
}

And this is its its AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    xmlns:tools="http://schemas.android.com/tools"
    package="de.abc.someapp.dynamic">

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

  <application
      android:allowBackup="false"
      tools:ignore="MissingApplicationIcon">
    <activity
        android:name="de.abc.someapp.dynamic.DynamicFeatureActivity"
        android:exported="true">

      <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </activity>
  </application>

</manifest>

The original project is quite big (>150 modules) which is why i didn't add the app build.gradle

Surely this doesn't help finding the real issue but i will try to give an outline.

:app main manifest sets the package 'de.abc.someapp' and has resource folders for different build types such as release.

release/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="GoogleAppIndexingWarning">

  <application
      android:supportsRtl="true"
      android:allowBackup="true"
      tools:replace="android:allowBackup"
      android:fullBackupContent="@xml/backup_rules"/>
</manifest>

release block in :app build.gradle

release {
      minifyEnabled true
      shrinkResources true
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard.pro', 'proguard-release.pro'
      debuggable false
      zipAlignEnabled true
      signingConfig signingConfigs.release
}

The given error was all which seemed useful out of a build with --stacktrace but it doesn't seem to helpful.

I wonder:

How does the merger come to the conclusion that :some_dynamic_feature module has the same package as app?

What is the underlying issue?

(Can't find anything pointing to that package also in the build/ folder of the feature module. )

How can i resolve this issue?


Solution

  • You need to delete the package definition from the manifest and use android.namespace attribute in you app module's build.gradle.