针对 Android 12 的清单合并失败 [英] Manifest merger failed targeting Android 12
问题描述
使用 Android Studio 4.2.1,在我的 build.gradle 文件中将 sdk 目标更改为 Android 12 后,我收到 Manifest merge failed with multiple errors, see logs
错误.
Using Android Studio 4.2.1, after changing sdk target to Android 12 in my build.gradle file, I am getting a Manifest merger failed with multiple errors, see logs
error.
Merged Manifest
标签中显示的错误如下:
The errors shown in the Merged Manifest
tab are as follows:
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 文件中.我只有一项活动.没有服务或广播接收器.见下文:
However the android:exported
tag is already applied in my AndroidManifest.xml file. I only have one activity. No services or broadcast receivers. See below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mydomain.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.mydomain.myapp.MyApplication"
android:allowBackup="false"
tools:replace="allowBackup"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.mydomain.myapp.ui.MainActivity"
android:exported="true">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>
我的 build.gradle(:app) 文件:
My build.gradle(:app) file:
android {
compileSdkVersion("android-S")
buildToolsVersion "30.0.3"
defaultConfig {
...
minSdkVersion 23
targetSdkVersion("S")
...
}
知道如何解决这个问题吗?
Any idea how I could resolve this issue?
推荐答案
该问题是由 3 个活动在 androidx.test:core
android:exported 属性引起的> 库版本 1.3.0
.升级到版本 1.4.0-beta01
修复了该问题.
The issue was caused by 3 activities missing the android:exported
attribute in the androidx.test:core
library version 1.3.0
. Upgrading to version 1.4.0-beta01
fixed the issue.
如果您在面向 Android 12 后遇到错误,最简单的调试方法是:
If you are getting errors after targeting Android 12, the easiest way to debug this is to:
- 降级到之前的 sdk 版本
- 重建项目
- 成功构建后,打开项目的
AndroidManifest.xml
. - 在窗口底部,点击
Merged Manifest
标签 - 查找任何包含
标记且缺少android:exported
属性的
- downgrade to a prior sdk version
- rebuild project
- after a successful build, open your project's
AndroidManifest.xml
. - at the bottom of the window, click on the
Merged Manifest
tab - look for any
<activity>
that includes an<intent-filter>
tag and is missing theandroid:exported
attribute
如果您想确保这些活动是问题所在,请将它们直接添加到您项目的 AndroidManifest.xml
文件中,并添加缺少的 android:exported
属性并尝试重建项目.
If you want to make sure these activities are the issue, add them directly to your project's AndroidManifest.xml
file with the missing android:exported
attribute added and try rebuilding the project.
因此,如果
缺少 android:exported
属性,请将其添加到您的 AndroidManifest.xml
文件如下:
So if <activity android:name="com.domain.ProblemActivity">
is missing the android:exported
attribute, add it to your AndroidManifest.xml
file like so:
<activity
android:name="com.domain.ProblemActivity"
android:exported="true" >
针对 Android 12 重新构建,如果它有效,那么您就找到了错误!
Rebuild targeting Android 12 and if it works, then you found the bug!
感谢 @MikePenz 为我指明了正确的方向.
Thanks @MikePenz for pointing me in the right direction.
这篇关于针对 Android 12 的清单合并失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!