android:exported 已添加,但仍然出现错误目标为 Android 12 及更高版本的应用需要为 android:exported 指定明确的值

android:exported added but still getting error Apps targeting Android 12 and higher are required to specify an explicit value for android:exported

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

错误- 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>

合并清单错误

Other Manifest Files (Included in merge, but did not contribute any elements) firebase-installations:17.0.0 manifest, versionedparcelable:1.1.1 manifest, runtime:1.0.1 manifest, test:core:1.2.0 manifest, loader:1.0.0 manifest, facebook-share:11.1.0 manifest, leakcanary:leaksentry:2.0-alpha-3 manifest, material-dialogs:input:3.2.1 manifest, material-icons-extended:1.0.0 manifest, play-services-stats:17.0.0 manifest, interpolator:1.0.0 manifest, activity-compose:1.3.1 manifest, material-ripple:1.0.0 manifest, foundation:1.0.0 manifest, asynclayoutinflater:1.0.0 manifest, savedstate-ktx:1.1.0 manifest, navigation-dynamic-features-fragment:2.3.5 manifest, firebase-ui-auth:7.2.0 manifest, animation:1.0.1 manifest, animation-core:1.0.1 manifest, installreferrer:1.0 manifest, firebase-crashlytics:18.0.0 manifest, ui:1.0.1 manifest, lifecycle-viewmodel-savedstate:2.3.1 manifest, play-services-auth-base:17.0.0 manifest, hilt-android:2.35.1 manifest, material-dialogs:core:3.2.1 manifest, AndroidManifest.xml navigation file, savedstate:1.1.0 manifest, cursoradapter:1.0.0 manifest, sqlite-framework:2.0.1 manifest, room-ktx:2.1.0 manifest, leakcanary-android-core:2.0-alpha-3 manifest, AndroidManifest.xml navigation file, media:1.0.0 manifest, coordinatorlayout:1.1.0 manifest, legacy-support-core-utils:1.0.0 manifest, lifecycle-runtime:2.3.1 manifest, coil-kt:coil:1.3.1 manifest, ui-tooling-preview:1.0.0 manifest, facebook-core:11.1.0 manifest, core:1.6.0 manifest, material:1.0.0 manifest, firebase-common:20.0.0 manifest, documentfile:1.0.0 manifest, lifecycle-viewmodel-compose:2.4.0-beta01 manifest, play-services-base:17.1.0 manifest, ui-tooling-data:1.0.0 manifest, coil-base:1.3.1 manifest, firebase-analytics-ktx:19.0.0 manifest, localbroadcastmanager:1.0.0 manifest, swiperefreshlayout:1.1.0-alpha03 manifest, constraintlayout-compose:1.0.0-beta02 manifest, core-ktx:1.6.0 manifest, firebase-database-collection:18.0.0 manifest, coil-compose-base:1.3.1 manifest, activity:1.3.1 manifest, AndroidManifest.xml navigation file, facebook-messenger:11.1.0 manifest, print:1.0.0 manifest, customview:1.1.0 manifest, material-icons-core:1.0.0 manifest, play-services-measurement-sdk:19.0.0 manifest, fragment:1.3.4 manifest, firebase-appcheck-interop:16.0.0-beta01 manifest, facebook-login:11.1.0 manifest, cardview:1.0.0 manifest, runtime-rxjava2:1.0.0 manifest, viewpager2:1.0.0 manifest, play-services-ads-identifier:17.0.0 manifest, play-services-measurement-impl:19.0.0 manifest, lifecycle-livedata-core:2.3.1 manifest, play-services-safetynet:17.0.0 manifest, AndroidManifest.xml navigation file, lifecycle-viewmodel-ktx:2.3.1 manifest, transport-backend-cct:3.0.0 manifest, fragment-ktx:1.2.4 manifest, appcompat:1.3.0 manifest, transport-runtime:3.0.0 manifest, lifecycle-livedata-core-ktx:2.2.0 manifest, firebase-firestore-ktx:23.0.0 manifest, legacy-support-v4:1.0.0 manifest, play-services-basement:17.1.1 manifest, firebase-storage:20.0.0 manifest, play-services-auth-api-phone:17.4.0 manifest, leakcanary-android:2.0-alpha-3 manifest, firebase-auth-interop:20.0.0 manifest, lifecycle-viewmodel:2.3.1 manifest, browser:1.0.0 manifest, firebase-auth:21.0.1 manifest, material:1.2.1 manifest, slidingpanelayout:1.0.0 manifest, vectordrawable:1.1.0 manifest, recyclerview:1.1.0 manifest, play-services-auth:19.0.0 manifest, room-runtime:2.1.0 manifest, dagger-lint-aar:2.35.1 manifest, navigation-dynamic-features-runtime:2.3.5 manifest, play-services-measurement-api:19.0.0 manifest, firebase-encoders-json:18.0.0 manifest, sqlite:2.0.1 manifest, facebook-android-sdk:11.1.0 manifest, firebase-components:17.0.0 manifest, transport-api:3.0.0 manifest, protolite-well-known-types:18.0.0 manifest, markdown-processor:0.1.3 manifest, play-services-measurement-base:19.0.0 manifest, firebase-common-ktx:20.0.0 manifest, activity-ktx:1.3.1 manifest, firebase-crashlytics-ktx:18.0.0 manifest, coil-compose:1.3.1 manifest, multidex:2.0.1 manifest, core-runtime:2.1.0 manifest, fragment-testing:1.2.0 manifest, ui-graphics:1.0.1 manifest, AndroidManifest.xml navigation file, ui-tooling:1.0.0 manifest, grpc-android:1.28.0 manifest, ui-unit:1.0.1 manifest, play-services-measurement:19.0.0 manifest, play:core:1.9.1 manifest, annotation-experimental:1.1.0 manifest, play-services-measurement-sdk-api:19.0.0 manifest, play-services-tasks:17.0.0 manifest, firebase-analytics:19.0.0 manifest, facebook-common:11.1.0 manifest, drawerlayout:1.1.1 manifest, AndroidManifest.xml navigation file, navigation-compose:2.4.0-alpha09 manifest, facebook-gamingservices:11.1.0 manifest, firebase-firestore:23.0.0 manifest, lifecycle-livedata:2.2.0 manifest, legacy-support-core-ui:1.0.0 manifest, test:monitor:1.2.0 manifest, AndroidManifest.xml navigation file, facebook-applinks:11.1.0 manifest, viewpager:1.0.0 manifest, ui-geometry:1.0.1 manifest, lifecycle-runtime-ktx:2.3.1 manifest, constraintlayout:2.0.4 manifest, ui-text:1.0.1 manifest, AndroidManifest.xml navigation file, firebase-installations-interop:17.0.0 manifest, transition:1.3.0 manifest, foundation-layout:1.0.1 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 navigation file Merging Errors: Error: 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. Dairy.app main manifest (this file) Error: 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. Dairy.app main manifest (this file) Error: 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. Dairy.app main manifest (this file)

构建失败后转到AndroidManifest.xml并在底部单击合并清单查看哪些活动具有 intent-filter 但没有 exported=true 属性。或者您可以只获取出错的活动。

使用 android:exported="true" 和应用 tools:node="merge" 将这些活动添加到您的应用程序清单中,这将添加导出的属性给出错误的活动。

Example:

      <activity
            android:name="<activity which is giving error>"
            android:exported="true"
            tools:node="merge" />

你将不得不这样做一次,你可以在库开发人员更新他们的库后删除它。

解决target sdk 31中的这个错误-

1.First of all set target sdk to 30

2.Then 转到合并清单

3.Find 如果有任何 activity、服务、接收方或提供者不具有 android:exported set.Override 所有这些条目并将其 android:exported 设置为对或错。

4.set 目标 sdk 回到 31 和 运行 项目

我遇到了这个问题,我将 android:exported="true"tools:node="merge" 添加到 AndroidManifest.xml,但是出现了这个错误。 我发现这与我的项目的 Activates 无关,而是与某些 依赖项 有关,如下所示:

implementation 'com.najva.sdk:najva-android-sdk:1.3.3'

所以检查一下你的项目依赖,你一定会找到的。

以下app/build.gradle可能是原因。

dependencies {
    debugImplementation androidx.fragment:fragment-testing:<1.4.0-alpha02 or lower>’
}
解决方案 1

fragment-testing 更新为 1.4.0-alpha03 或更高版本。

解决方案 2

将以下内容添加到 AndroidManifest.xml

<manifest>
    <application>
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
            android:exported="false" />
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
            android:exported="false" />
        <activity
            android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
            android:exported="false" />
    </application>
</manifest>

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

此问题源于项目的依赖关系。右键单击 intent-filter 和 select 查找用法选项。现在,在所有使用地方检查是否导出赋值或 nor。如果没有,请分配一个值(即使在库的缓存文件夹中)。这将解决问题,直到缓存刷新,但您已经确定了造成此问题的库。

如果您使用 ogury Ads,请将其放入您的 AndroidManifest 文件中

 <activity
        android:name="io.presage.mraid.browser.ShortcutActivity"
        android:theme="@style/Presage.AdScreen"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>

如果您使用的是 flutter,请将 flutter_local_notifications 升级到最新版本(现在是 9.3.2)为我解决了这个错误..

另见

感谢@faizy,@Android 开发者我做了这个。

将这些库升级到新版本:

androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.fragment:fragment-testing:1.4.1"
androidTestImplementation "androidx.test:core:1.4.0"

我在这些依赖项中用 androidTestImplementation 替换了 debugImplementation

Sync Project with Gradle Files。 运行 项目(或重建,或 运行 Lint)。可能不会有帮助。那你应该做这个。

  1. targetSdkVersion 降级到 30。

运行 再次项目。可能会编译。

在我的例子中,所有需要的 android:exported="true"android:exported="false" 出现在合并 [=] 的 activityservicereceiverprovider 中22=] 其中 <intent-filter> 发生。

要找到合并的 AndroidManifest,切换到 Project 并展开 app 模块,然后构建 > 中间体 > merged_manifest > 调试。

如果缺少某些 android:exported,请找到相应的 AndroidManifest 并添加到那里。

  1. targetSdkVersion 升级到 31。

运行 再次项目。如果它不会编译,可能你应该重建项目。与往常一样,构建 > 重建项目,文件 > 使缓存无效 > 使并重新启动无效。

一段时间后(几次 gradle 同步,Android Studio 重新启动)编译。

解决问题:

1- targetSdkVersion 如果 31 变为 30

2-在AndroidManifest里面添加一行android:exported="true" />