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
OPTION 1
You need to set
android:exported
to eithertrue
orfalse
in yourAndroidManifest.xml
.(which you have done)OPTION 2
AndroidManifest.xml
.<activity>
that includes an<intent-filter>
tag and is missing theandroid:exported
attributeAndroidManifest.xml
file with the missing android:exported attribute added and try rebuilding the project.If
<activity android:name="com.example.MainActivity">
is missing theandroid:exported
attribute, add it to yourAndroidManifest.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!
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.
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 inStep2: After you find the services / packages missing the
android:exported=”false” or android:exported=”true”
, we will copy those activities directly toapp/src/res/AndroidManifest.xml
and add inandroid:exported=”false” or android:exported=”true”
.