Search code examples
javaandroidandroid-studioandroid-emulatorruntime-error

Android Studio error: "Manifest merger failed: Apps targeting Android 12"


I have updated my emulator version and Android SDK version to Android S (Android 12). After the update, I cannot run the project. I cannot run a Hello, World! project (empty project), but I can build Gradle as well as, but I can not run the project. I always got the 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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

How can I fix it?

Here is a screenshot:

This is a screenshot.

How can I solve this issue when using Android 12 SDK?

This question is about the issue after applying the solution to this, and is different than this question. Also, this question is older than this.


Solution

  • You need to specify android:exported="false" or android:exported="true"

    Manifest:

    <activity
        android:name=".MainActivity"
        android:exported="true"
        android:theme="@style/Theme.MyApplication.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    as mentioned in the document:

    If your app targets Android 12 and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the android: exported attribute for these app components.

    Warning: If an activity, service, or broadcast receiver uses intent filters and doesn't have an explicitly-declared value for android:exported, your app can't be installed on a device that runs Android 12.

    Also check when to use true/false for the 'android:exported' value.