Android 引入动态功能模块后发布版本的清单合并失败

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

为我的 android 项目组装发布版本时出现以下错误:

> 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

模块'some_dynamic_feature'是一个新创建的模块,设置为动态功能模块。

这是它的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
}

这是它的 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>

原来的项目很大(>150 个模块)这就是为什么我没有添加应用程序的原因build.gradle

当然这无助于找到真正的问题,但我会尝试给出一个大纲。

:app main manifest 设置包 'de.abc.someapp' 并具有用于不同构建类型的资源文件夹,例如发布。

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>

在 :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
}

给定的错误是所有在使用 --stacktrace 的构建中似乎有用的错误,但它似乎没有帮助。

我想知道:

合并怎么得出结论:some_dynamic_feature模块和app有相同的包?

根本问题是什么?

(在功能模块的 build/ 文件夹中也找不到指向该包的任何内容。)

我该如何解决这个问题?

您需要从清单中删除包定义并在应用模块的 build.gradle 中使用 android.namespace 属性。