Navid Abutorab
Navid Abutorab

Reputation: 1787

android - Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported`

I've updated my SDK version to 31, afterward I get this error. this is my Gradle :

    android {
    compileSdkVersion 31

    defaultConfig {
        applicationId "com.persiandesigners.alldentshops"
        minSdkVersion 16
        targetSdkVersion 31
        vectorDrawables.useSupportLibrary = true
        versionCode 1
        versionName "1"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
    implementation 'androidx.cardview:cardview:1.0.0-alpha01'
    implementation 'com.google.android.material:material:1.2.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'

I get this error : Manifest merger failed : 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.

I did what it says, this is my manifest code :

<activity
        android:name="mypackage.MainActivity"
        android:exported="true"
        tools:node="merge"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/SplashScreenTheme"
        android:windowSoftInputMode="stateAlwaysHidden">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

this is the launcher activity and I've added android:exported tag , I tried clean and rebuilt but It didn't work . I still gets mergin error in manifest merge :

Merging Errors: Error: android:exported needs to be explicitly specified for <activity>. 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. forushgah_alldentalshop.app main manifest (this file)

it's pointed to the MainActivity activity

Upvotes: 5

Views: 6947

Answers (3)

MEGHA RAMOLIYA
MEGHA RAMOLIYA

Reputation: 1927

In your manifest, add android:exported="true" or android:exported="false " in your default launching activity attribute.

In launcher activity

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

In receiver

<receiver android:name=".Musicreceiver"
          android:exported="true">

</receiver>

In services

    <service
        android:name=".service.PlayerService"
        android:exported="true"
        android:enabled="true" />

Upvotes: 0

Amer Al zibak
Amer Al zibak

Reputation: 1951

if you are using flutter ,may some deprecated lib in your app is causing this.. in my case: upgrading flutter_local_notifications to the latest version (now is 9.3.2) solved this error..

Upvotes: 3

Pramod Moolekandathil
Pramod Moolekandathil

Reputation: 589

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 these app components.

Please note this is applicable to all the activities, services, broadcast receivers that use an intent-filter.

Make the changes. Save it. Invalidate cache and restart android studio and check.

Upvotes: 2

Related Questions