skip to Main Content

After upgrading to Android Studio Dolphin | 2021.3.1, the application is not compiling. It shows

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

I have set all the activity with android:exported="false". But it is still showing this issue.

My manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.something">
 <application
    android:requestLegacyExternalStorage="true"
    android:label="something"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:exported="false"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize"
        >

        <meta-data
          android:name="io.flutter.embedding.android.NormalTheme"

          android:resource="@style/NormalTheme"
          />
       

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

My gradle file:

 def localProperties = new Properties()
  def localPropertiesFile = rootProject.file('local.properties')
  if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
    localProperties.load(reader)
   }
}  

 def flutterRoot = localProperties.getProperty('flutter.sdk')
 if (flutterRoot == null) {
    throw  GradleException("Flutter SDK not found. Define location with flutter.sdk in 
 the local.properties file.")
 }

 def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
 if (flutterVersionCode == null) {
   flutterVersionCode = '11'
 }

 def flutterVersionName = localProperties.getProperty('flutter.versionName')
  if (flutterVersionName == null) {
   flutterVersionName = '11.0'
  }

 apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
 apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
 apply plugin: 'com.android.application'
 apply plugin: 'com.google.gms.google-services'
 def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
 if (keystorePropertiesFile.exists()) {
 keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

 android {

    compileSdkVersion 33

    sourceSets {
     main.java.srcDirs += 'src/main/kotlin'
    }

   defaultConfig {
    // TODO: Specify your own unique Application ID 
    (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.something.something1.com"
    minSdkVersion 21
    targetSdkVersion 33
    multiDexEnabled true
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
   }
   signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? 
    file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
   }
   buildTypes {
       release {
        signingConfig signingConfigs.release
       }
   }

 }

   flutter {
     source '../..'
}

   dependencies {
    implementation platform('com.google.firebase:firebase-bom:28.2.1')
    implementation 'com.google.firebase:firebase-analytics'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}   

3

Answers


  1. OPTION 1

    You need to set android:exported to either true or false in your AndroidManifest.xml.(which you have done)

    OPTION 2

    1. Downgrade your project to an older SDK version, then rebuild project.
    2. After a successful build, open your project’s AndroidManifest.xml.
    3. Click on the Merged Manifest tab at the bottom of the file and search for any <activity> that includes an <intent-filter> tag and is missing the android:exported attribute
    4. To confirm that these activities are the issue, add them directly to your project’s AndroidManifest.xml file with the missing android:exported attribute added and try rebuilding the project.

    If <activity android:name="com.example.MainActivity"> is missing the android:exported attribute, add it to your AndroidManifest.xml file.

    OPTION 3

    You are using a library that doesn’t target Android 12 yet. You can either upgrade the version if there is or remove it.

    Good luck!

    Login or Signup to reply.
  2. If you got this messages from your android studio, in your main activity add in android:exported=”false” or android:exported=”true” will solved this issue.

    Login or Signup to reply.
  3. if you are using other packages or libraries, some of these libraries may not have set android:exported=”false” or android:exported=”true” in their Manifest files.

    If you do not want to update those packages to the latest, we will have to over-ride their manifest files in the app’s Manifest file.

    So Step 1 is to find which package/libraries manifest files are missing the android:exported=”false” or android:exported=”true” .

    This is done by downgrading your targetSdkVersion to 30 so that it compiles correctly. When the app compiles correctly it will generate a mergedManifest file in

    build/app/intermediates/merged_manifests/debug/AndroidManifest.xml and 
    build/app/intermediates/merged_manifest/debug/AndroidManifest.xml
    

    Step2: After you find the services / packages missing the android:exported=”false” or android:exported=”true”, we will copy those activities directly to app/src/res/AndroidManifest.xml and add in android:exported=”false” or android:exported=”true”.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search