【问题标题】:Android manifest merging fails for release builds after introducing dynamic feature module引入动态功能模块后,发布版本的 Android 清单合并失败
【发布时间】:2021-12-22 08:49:00
【问题描述】:

为我的 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 个模块),这就是我没有添加 app build.gradle 的原因

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

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

发布/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/ 文件夹中也找不到指向该包的任何内容。)

我该如何解决这个问题?

【问题讨论】:

标签: android android-manifest dynamic-feature-module


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-12
    • 2023-03-26
    • 2017-09-03
    • 1970-01-01
    • 2015-07-24
    • 1970-01-01
    相关资源
    最近更新 更多