清单合并失败:需要为 <activity> 明确指定 android:exported

Manifest merger failed : android:exported needs to be explicitly specified for <activity>

我的清单文件有问题,错误消息:

Manifest merger failed : android: exported needs to be explicitly specified for . 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.

我的 AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyTheme">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:exported="true"
            android:name=".Activities.SplashScreenActivity"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        </activity>
    </application>

</manifest>

描述了一个解决方案,但它不起作用或者我做错了什么。也许有人有类似的问题,请告诉我如何解决。

  1. 降级或升级到之前的 sdk 版本,然后重建项目。
  2. 打开您项目的 AndroidManifest.xml
  3. 单击[window底部的合并清单选项卡]
  4. 找出包含 <intent-filter> 标签的 <activity> 缺少 android:exported 属性
  5. 如果找到则右键单击并按 Go to Declaration 然后将 android:exported 属性添加到 activity 标签
  6. 重建项目

希望它能奏效。它对我有用。