构建Android12及以上报错:Apps targeting Android12 and higher are required to specify...

问题描述:

在Android Studio中,如果build.gradle中,
targetSdkVersion 33

即以 >= android1为目标版本,如果logcat提示以下的错误:
Manifest merger failed : 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.

根据提示,也就是需要在manifest中的Activity或者广播等加上`android:exported="false"`
至于值设为是true还是false,需要自己根据你的需求场景去决定了。

问题原因:

如果应用以 >=Android 12 或更高版本为目标平台,且包含使用 intent 过滤器的 activity、服务或广播接收器,您必须为这些应用组件显式声明 android:exported 属性。目的就是Android 12 提高了app和系统的安全性。

注意事项:

此元素设置 Activity 是否可由其他应用的组件启动:
如果设为“true”,那么 Activity 可由任何应用访问,并且可通过其确切类名称启动。
如果设为“false”,则 Activity 只能由同一应用的组件、使用同一用户 ID 的不同应用或具有特权的系统组件启动。 没有 intent 过滤器时,这是默认值。
如果应用中的 Activity 包含 intent 过滤器,请将此元素设置为“true”,以允许其他应用启动该 Activity。例如,假设 Activity 是应用的主要 Activity,并且包含 category“android.intent.category.LAUNCHER”。

如果此元素设为“false”,并且应用尝试启动该 Activity,系统会抛出 ActivityNotFoundException。

注意:对于BroadcastReceiver组件一样,凡是有<intent-filter>标签的组件,都需要加上android:exported

猜你喜欢

转载自blog.csdn.net/u010231454/article/details/132036339