首页 > 解决方案 > 添加了 android:exported 但仍然出现错误 需要针对 Android 12 及更高版本的应用程序才能为 android:exported 指定显式值

问题描述

我已添加android:exported="true"到清单中的唯一活动,但在将编译 sdk 和目标 sdk 版本更新为 31 后仍然出现错误。我还尝试重建项目,使缓存无效并重新启动,但这没有帮助

错误- 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.xyz.abc">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:name=".framework.presentation.BaseApplication"
        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/AppTheme">
        <activity android:name="com.xyz.presentation.MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

合并清单错误

appcompat-resources:1.3.1 manifest, runtime-livedata:1.0.0 manifest, runtime-saveable:1.0.1 manifest, firebase-measurement-connector:19.0.0 manifest, vectordrawable-animated:1.1.0 manifest, main nav_graph。 xml 导航文件合并错误:错误:需要为 . 面向 Android 12 及更高版本的应用需要为android:exported当相应的组件定义了意图过滤器时。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported。Dairy.app 主清单(此文件)错误:需要为 . 面向 Android 12 及更高版本的应用需要为android:exported相应组件定义了 Intent 过滤器时指定显式值。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported。Dairy.app 主清单(此文件)错误:需要为 . 面向 Android 12 及更高版本的应用需要为android:exported当相应的组件定义了意图过滤器时。有关详细信息,请参阅 https://developer.android.com/guide/topics/manifest/activity-element#exported。Dairy.app 主清单(此文件)

标签: androidandroid-manifestmanifestandroid-12targetsdkversion

解决方案


androidx.test:core库版本 1.3.0。升级到 1.4.0 版解决了这个问题。


推荐阅读