针对Android12的清单合并失败

使用 Android Studio 4.2.1,在我的 build.gradle 文件中将 sdk 目标更改为 Android 12 后,出现Manifest merger failed with multiple errors, see logs错误。

Merged Manifest选项卡中显示的错误如下:

Merging Errors: 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
Merging Errors: 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
Error: Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 

但是,该android:exported标记已应用在我的 AndroidManifest.xml 文件中。我只有一项活动。没有服务或广播接收器。见下文:

我的 build.gradle(:app) 文件:

android {
    compileSdkVersion("android-S")
    buildToolsVersion "30.0.3"

    defaultConfig {
        ...
        minSdkVersion 23
        targetSdkVersion("S")
        ...
}

知道我如何解决这个问题吗?

回答

该问题是由 3 个活动android:exportedandroidx.test:core库版本中缺少该属性引起的1.3.0。升级到版本1.4.0-beta01解决了这个问题。

如果您在面向 Android 12 后遇到错误,最简单的调试方法是:

  • 降级到之前的 sdk 版本
  • 重建项目
  • 成功构建后,打开项目的AndroidManifest.xml.
  • 在窗口底部,单击Merged Manifest选项卡
  • 查找任何<activity>包含<intent-filter>标签但缺少该android:exported属性的内容

如果您想确保这些活动是问题所在,请将它们直接添加到您的项目AndroidManifest.xml文件中,并android:exported添加缺失的属性,然后尝试重建项目。

因此,如果<activity android:name="com.domain.ProblemActivity">缺少该android:exported属性,请将其添加到您的AndroidManifest.xml文件中,如下所示:

<activity 
 android:name="com.domain.ProblemActivity"
 android:exported="true" >

针对 Android 12 重新构建,如果它有效,那么您就找到了错误!

感谢@MikePenz为我指明了正确的方向。

  • 通过运行 `gradlew processDebugAndroidTestManifest --debug` 并向上滚动到显示“面向 Android 12 及更高版本的应用程序...”文本的位置,我能够找出导致我的项目出现问题的原因。在我的例子中,上面的 INFO 行显示了需要更新到 3.4.0 的合并浓缩咖啡。另一个需要更新的是 WorkManager。

以上是针对Android12的清单合并失败的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>