android:export when migrating to Android 12 in Flutter AndroidManifest - android

I'm migrating my flutter app to Android 12 and I don't know where exactly I've to put the android:export lines in my AndroidManifest.
I've tries several options but always the console throws me an error about this.
This is my AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.atgapp.atgapp">
<application
android:label="atgapp"
android:name="${applicationName}"
android:icon="#mipmap/icono"
android:exported="true">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/icon" />
<activity
android:name=".MainActivity"
android:exported="true"
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>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
Thank you for your help

Just update your Service tag
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

First, if you open the app in Android Studio and go through your Manifest you should find warnings for exporting services/activities, fix those by adding the suggested.
After, you should create a API 31 emulator (with Android 12) and try running your app, you will probably receive an error caused by some library that is not updated, like the following:
Installation did not succeed. The application could not be installed:
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
List of apks: [0]
'C:\Users\------\Desktop-----\=====\mobile\build\outputs\apk\debug\mobile-debug.apk'
Installation failed due to: 'INSTALL_PARSE_FAILED_MANIFEST_MALFORMED:
Failed parse during installPackageLI:
/data/app/vmdl1980686865.tmp/base.apk (at Binary XML file line #294):
com.instacart.library.truetime.BootCompletedBroadcastReceiver:
Targeting S+ (version 31 and above) requires that an explicit value
for android:exported be defined when intent filters are present'
for the example above, the library TrueTime is outdated, updating it resolved the problem.

Related

You uploaded an APK or Android App Bundle which has an activity, ... receiver with intent filter, but without 'android:exported' property set

I already added android:exported="true" to all the activities in my manifest file but still got the following error:
You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without 'android:exported' property set. This file can't be installed on Android 12 or higher.
This is my Manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nelinik.TheQuizBattleApp">
<queries>
<provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
</queries>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.INTERNET"/>
<!-- needed for notifications-->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name="${applicationName}"
android:label="The Quiz Battle"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
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">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Facebook -->
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<meta-data android:name = "com.facebook.sdk.ClientToken" android:value = "#string/facebook_client_token" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:exported="true"
/>
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<!-- Add Mob -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-9722761268400847~5659867972"/>
<!-- 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>
</manifest>``
I solved the problem by running the app with Android 12. The console displayed which manifest file caused the error.
It was a manifest file from a plugin.
There are two options to solve the problem:
update the plugin, the problem might be solved with a newer version
add the 'android:exported' property to the file of the plugin

Trying to upgrade SDK version but error "Apps targeting Android 12 and higher are required to specify an explicit value"

I'm trying to upgrade my SDK Version from 30 to 31, and add some android:export="true"
to my manifest but still got error Error: 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.
Here for my manifest
<application
android:name=".app.MyApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="#style/NoActionBar">
<activity android:name=".ui.SplashScreen"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="false"
android:theme="#style/NoActionBar"
android:windowSoftInputMode="stateHidden"/>
<service
android:name=".firebase.FcmServices"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
What's wrong with my codes? Is there something missing?
Actually it works fine, and the docs show it too:
https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceIdService
https://firebase.google.com/docs/cloud-messaging/android/client#manifest
Weird thing is that when I tested it initially, it didn't work. Only later. No idea how it's possible. Probably some bug on Android.
Anyway, this is from the docs:
<service
android:name=".java.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- FirebaseInstanceIdService performs security checks at runtime,
no need for explicit permissions despite exported="true" -->
<service android:name=".MyFirebaseInstanceIdService" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

uploading bundle in play store getting error

You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#exported
Getting this error in play store console while uploading bundle in play store console
Manifest file code
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smartbharat.one">
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<application
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher"
android:usesCleartextTraffic="true">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDPzRxpT0mhrdEjTipEadB0l8T2tyu3m5E"/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_notification" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true"
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">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"/>
<!-- 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>
</manifest>
changing target sdk to 30 worked for me.
There is an easy fix to this which is setting the max supported version with 30 instead of 31 in your build.gradle file/files
However to support 31:
From the documentation
**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.
If the app component includes the LAUNCHER category, set android:exported to true. In most other cases, set android:exported to false.
**
<service android:name="com.example.app.backgroundService"
android:exported="false">
<intent-filter>
<action android:name="com.example.app.START_BACKGROUND" />
</intent-filter>
</service>
PS: I would suggest using the canary version of android studio and build your project because it's listing would show you the errors in the manifest.
From the looks of it one of your activities is not setting exported.
Replace
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"/>
and
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
with
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:exported="true" />
and
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:exported="true"/>

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

Please help me with this error getting in my project while trying to run at mobile via android studio.
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.
Add this to your manifest to the activity tag in the error message:
android:exported="true"
This happens when your activity can be started by another application. For example image viewer can be started by file manager when clicking an image. The image viewer app is "exported".
It's also always required if you are using the following code necessary for dynamic links:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
Example:
<activity
android:name=".MainActivity"
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"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
I found this solution!!.
So you have to add the android:exported="true" into the activity tag in the manifest (not in the application).
<application
android:fullBackupContent="#xml/my_backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name">
<activity android:name=".yourActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".otherActivity" android:exported="true"/>
</application>
To see more information about the exported property, see App manifest file activity
:)
if you are using flutter ,may some deprecated lib in your ap is causing this ..
for me: upgrading flutter_local_notifications to the latest version (now is 9.3.2) solved this error..
If you have any activity, service, receiver, or provider that does not have exported set in your manifest file then add whenever it needed like,
android:exported="false or true"
You had to figure out the component missing the Android exported tag.
You should downgrade your SDK version and check the final merged manifest file for the components missing the exported tag but has IntentFilter.
The step-by-step instructions is provided in this link.
This is for the projects using Bootsplash.
My project used Bootsplash and I solved it by adding android:exported="true" also to the activity of Bootsplash in the AndroidManifest file.
<application
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan"
android:exported="true" // <----ADD THIS
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.zoontek.rnbootsplash.RNBootSplashActivity"
android:theme="#style/BootTheme"
android:exported="true" // <----ADD THIS
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Add android:exported="true" into the Manifest file inside of the application activity
<application
<activity
android:exported="true"
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.NoteKeeper.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

"Please configure Android SDK" error show up after adding Facebook login in flutter project

I am developing a flutter application which use firebase and Facebook login.
My app is working perfectly after adding firebase authentication. But after I add Facebook login I can no longer build the project. The console show 'Finished with error: Gradle task assembleDebug failed with exit code 1'.
When I check the logcat, it tells me to "Please configure android SDK".
When I click it, the below image show up
android sdk configuration
This is my AndroidManifest.xml
package="com.example.flutter_bloc_test_project">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_bloc_test_project"
android:icon="#mipmap/ic_launcher">
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
I have tried method like Downgrading gradle version. But the firebase won't work with low version that's why I had to upgrade in the first place.
Please help

Categories

Resources