Error when building Android12 and above: Apps targeting Android12 and higher are required to specify...

Problem Description:

In Android Studio, if
targetSdkVersion 33 in build.gradle

is >= android1 as the target version, if logcat prompts the following error:
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.

According to the prompt, you need to add `android:exported="false"` to the Activity or broadcast in the manifest.
As for whether the value is set to true or false, you need to decide according to your demand scenario.

problem causes:

If your app targets >= Android 12 or higher and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the android:exported attribute for those app components. The purpose is that Android 12 improves the security of apps and systems.

Precautions:

This element sets whether the Activity can be launched by components of other apps:
if set to "true", the Activity is accessible by any app and can be launched by its exact class name.
If set to "false", the activity can only be launched by components of the same application, different applications using the same user ID, or privileged system components. This is the default value when there is no intent filter.
If the activity in your app contains an intent filter, set this element to "true" to allow other apps to launch the activity. For example, assume that the Activity is the main Activity of the application and contains the category "android.intent.category.LAUNCHER".

If this element is set to "false" and the app attempts to start the Activity, the system will throw ActivityNotFoundException.

Note: Same as the BroadcastReceiver component, any component with an <intent-filter> tag needs to add android:exported

Guess you like

Origin blog.csdn.net/u010231454/article/details/132036339