Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present] - flutter

While debugging the application in android 12, the app is getting crashed.

Android 12 require you to add a piece of code to your main activity
Go to your project folder and open AndroidManifest.xml file
Add the below code in activity
android:exported="true"
Reference:
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme">
</activity>

In AndroidManifest.xml add android:exported="true":
<manifest ...>
<application ...>
<activity
android:exported="true"

In Android 11 and lower, when declaring an Activity, Service, or Broadcast receiver in AndroidManifest, you did not explicitly declare android:exported. Since the default value is exported=true, you only need to declare exported=false when you do not want to disclose to the outside.
<activity android:name="com.example.app.backgroundService">
<intent-filter>
<action android:name="com.example.app.START_BACKGROUND" />
</intent-filter>
</activity>
Android 12 Changes: Explicit declaration of exported
Apps that set SDK API 31 (android 12) as Target sdk on Android 12 devices must explicitly declare exported in components such as Activity that declared intent-filter. Otherwise, the following error occurs and the installation fails.
Targeting S+ (version 10000 and above) requires that an explicit value for
android:exported be defined when intent filters are present
The application could not be installed: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Even for apps targeting SDK API 31, components without intent-filter can omit the exported declaration.
You must explicitly declare exported as follows:
<service android:name="com.example.app.backgroundService"
android:exported="false">
<intent-filter>
<action android:name="com.example.app.START_BACKGROUND" />
</intent-filter>
</service>
Intent-filter is one of the methods for exposing the app's component to the outside. This is because the component of my app can be executed through the resolving of the implicit intent.
On the other hand, there are many cases where it is used for the purpose of executing a component with an implicit intent only inside my app, but it is exposed to the outside because exported is not set, and this may affect the resolving of the implicit intent. .

Thanks #rahul-kavati.
For Xamarin/MAUI it is a property on ActivityAttribute, used like this [Activity(Label = "MsalActivity", Exported = true)]

In Xamarin.Android I faced the same in BroadcastReceiver:
[BroadcastReceiver(Enabled = true, Exported =true)]
[IntentFilter(new[] { BluetoothDevice.ActionFound, BluetoothDevice .ActionUuid, BluetoothDevice .ExtraRssi})]
public class BleReceiver : BroadcastReceiver
and solved with the same Exported=true

The fastest way is to modify the targetSdkVersion in app/build.gradle, the maximum is 30

In AndroidManifest.xml
<activity
android:exported="true"
android:name="com.YOU.APP.activities.MainActivity"
android:launchMode="singleTask"
android:hardwareAccelerated="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

If you are using any intent filter or service it must have the android:export property

Currenty if you set minsdk version and get Android 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 then I have sollution of that..
Open platforms/android/android.json
Put this line in all plugin you used. android:exported="true" or android:exported="false" (Based on your requirement)
Image Link => https://drive.google.com/file/d/1uAtudZf5iRXUN2tWJvgxsaWeEuZmCUqh/view?usp=sharing
After open platforms\android\app\src\main/AndroidManifest.xml file and delete the plugin activity,meta-data,service,provider..and other things under <application .......>
---Do not delete launcher activity (first activity)--
---delete other data---
Because we changed android.json line. So when we build again than It will auto generate with android:exported..
I spend my whole day in this error. But now I am happy because I got Sollution.

Related

Deployed Flutter application to Google Play Store but it's stuck at the splash screen

Deployed Flutter application to Google Play Store but it's stuck at the splash screen and never open
I did match my AppID and still facing the same issue
Here is my manifest.xml:
<!-- TODO: Changed by Parveen Before merge 1 -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mrbox.store">
<uses-permission android:name="android.permission.INTERNET" />
<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_NETWORK_STATE" />
<!--
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.
-->
<!-- TODO: Add By Parveen before merge 1 -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Mr.Box Store"
android:usesCleartextTraffic="true"
android:icon="#mipmap/launcher_icon">
<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">
<!--
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>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!--
TODO: Changed by parveen before merge 1
android:name="default-url"
android:value="https://inspireui.com"
-->
<meta-data
android:name="default-url"
android:value="https://www.mrboxstore.com" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- TODO: Changed by parveen before merge 1 android:value="inspireui.com" -->
<data android:scheme="https"
android:host="mrboxstore.com" />
<data android:scheme="http" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/logo" />
<!--
Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message.
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/notiColor" />
<!-- Google map and Admod setup -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/api_key" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/admob_api" />
<!-- Facebook Login configuration -->
<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"
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>
<!--
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>
Things to try
Make sure flutter doctor -v runs without ANY complaints
Edit android/gradle.properties and add the flag: android.bundle.enableUncompressedNativeLibs=false
Do a flutter clean command
Try creating a release build using flutter build appbundle
Test Locally / Offline
download bundletool
Generate a set of APKs from your app bundle, following this guide
Deploy the app to your connected device(s) following this Guide
Works?
Upload your bundle to Google Play using the internal test track, or the alpha or beta channels to test the bundle before releasing it in production
Instructions for doing this can be found here
Good Luck :)
Because it is not working after uploading on google play. then there might be some issue with your app signing. You can follow the steps here
I have faced issues like this when I used facebook login sdk, so I would suggest checking following:
Check if you have signed the apk/appbundle with proper release keystore
Check if you have opt in for google's automatic signing on playstore while deploying app
2.1 If yes then it will change the sha-1 value which is used in facebook app for authentication, for it to work use the one generated by google in playstore
Assuming that you publish an App Bundle (.aab file) the issue can be related to the format itself since it is not testable via IDE. E.g. when running the app in Release mode on a device .apk is created and provisioned to it, not .aab.
What I did in the past to troubleshoot .aab (also had failures only with GPlay version, local Debug and Release modes worked fine) was to use Firebase Test Lab. You can run automated monkey tests on 5 physical devices and 15 virtual devices every day free-of-charge. Just log in to Firebase Console, cretae an empty project, go to Test, upload your .aab file, select devices (it's worth also to choose different locales) and wait for completion. After that check logs in test results, you might find answers there (in my cases there was an issue with localization resources which got broken while producing .aab release package).
This option can be esier/faster than splitting .aab locally with comand line into APKs and testing on a local device.
In my experience, try to check your database(sqlite) if created. Try to replace the path and check if the database is created properly.

Flutter - Local Notifications fail in release mode

I added the flutter_local_notifications plugin to schedule notifications. In the debug version everything works well for both emulators and real devices.
However, when I build the app
flutter build apk --split-per-abi
and install the package on a device and run the app, when it comes to the code part that marks the notification (I supposed...) , the app crashes
How do I find out what's wrong?
I followed the plugin developers instructions and changed the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.explika">
<uses-permission android:name="android.permission.INTERNET" />
<!-- Tudo relacionado com as notificações -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Fim relacionado com notificações -->
<!-- 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="Explika"
android:icon="#mipmap/ic_launcher">
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<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>
</manifest>
I found out what is causing the application to crash:
[ERROR: flutter / shell / platform / android / platform_view_android_jni.cc (39)] java.lang.AssertionError: java.lang.NoSuchFieldException: Drawable
However, this only happened in the Release version. The solution consists of customizing the ProGuard configuration file and the build.gradle file following the instructions on the plugin page.
I didn't do these steps because until then the Release version worked without problems and because I thought ProGuard configuration file would only be necessary in case want to publish on the Play Store.

Tracking App Install not working on Flutter app (Android) : CampaignTrackingReceiver is not registered, not exported or is disabled

I have implemented Firebase Analytics inside a Flutter app.
It's tracking fine all events but now I'm trying to add the Google Analytics receiver to track the source when the app is downloaded and successfully installed from the play store (coming from a link with campaign's parameters utm_source...)
In my Manifest I added these lines (inside the application tag):
<!-- Used for Google Play Store Campaign Measurement-->
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:enabled="true"
android:exported="false" />
Then I tried to test following these steps: Testing Google Play Campaign Measurement
From the console the ADB returned:
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.example.analyticsecommtest/com.google.analytics.tracking.android.AnalyticsReceiver (has extras) }
Broadcast completed: result=0
But when I run the installed app on the logcat I see:
CampaignTrackingReceiver is not registered, not exported or is disabled
Instead of:
Received installation campaign: source=testSource
Any suggestions on how to solve this?
I found the solution (at least for my case),
It's probably due to a lot of docs that can create confusion.
Using this:
<!-- Used for Google Play Store Campaign Measurement -->
<receiver
android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
android:permission="android.permission.INSTALL_PACKAGES"
android:enabled="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
solved the issue.

Eclipse imported but default activity not found

I just imported my eclipse project to android studio, and It studio converted everything fine. But while running the error message shows: Default Activity Not Found.
my manifest file: https://hastebin.com/yigakupoho.xml
You need to define your default activity as android.intent.action.MAIN, like that:
<activity android:name=".YourActivity" android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>

Unity firebase notifications custom image

I have decided to implement Firebase notifications into my unity project. The issue is that for notifications I want to use custom image, but that image is also used as app image (app_icon). I tried to modify manifest where I put into MessagingUnityPlayerActivity activity custom notification image (notificon) for displaying notification icon.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="${applicationId}"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name"
android:icon="#drawable/app_icon">
<!-- The MessagingUnityPlayerActivity is a class that extends
UnityPlayerActivity to work around a known issue when receiving
notification data payloads in the background. -->
<activity android:name="com.google.firebase.MessagingUnityPlayerActivity"
android:label="#string/app_name"
android:icon="#drawable/notificon"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<service android:name="com.google.firebase.messaging.MessageForwardingService"
android:exported="false"/>
</application>
</manifest>
I tried to modify it and delete some tags, but then the build wond compile. I should also mention that I have multiple manifests in my project and tried them to merge together but unsuccessfully. But this shouldnt be the problem since this is the only manifest with android:icon propery.
Thank you
Make an image (a white on transparent version of game icon, png) under folder "Assets\Plugins\Android\res\drawable.
In my case, the name of my image is "small_icon.png" then in "Assets\Plugins\Android\AndroidManifest.xml", add it after opening tag:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/small_icon" />
Your AndroidManifest.xml should be like
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" package="${applicationId}"
android:versionCode="1" android:versionName="1.0">
<application android:label="#string/app_name" android:icon="#drawable/app_icon">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/small_icon" />
<activity android:name="com.google.firebase.MessagingUnityPlayerActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
....
Putting a res folder inside Assets/Plugins/Android using AAB is obsolete and will prevent you from building.
Since I was too lazy to install Android Studio to build a custom AAR I solved it by placing a ZIP-Archive into the Assets/Plugins/Android folder, with the res folder inside (res folder created with this as mentioned in an other answer) and the following snippet inside a AndroidManifest.xml next to the res folder:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.google.firebase.messaging"
android:versionCode="1"
android:versionName="1.0">
<application>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/YOURICONIMAGENAMEWITHOUTEXTENSION" />
</application>
</manifest>
Then change the ZIP file extension to AAR in the explorer.
You can then specify the icons name from the senders side.
More details of the AAR anatomy here.
No need to change the manifest. This worked for me:
So you should be able to add your
icon(s) to
Assets/Plugins/Android/res/drawable/
and reference it name
Then, in the notification json, specify your icon. For example:
"notification": {
"title": "Title",
"body" : "First Notification",
"text" : "Text",
"icon" : "MyIcon"
}
Note: I used one of these icons.
Then change the ZIP file extension to AAR in the explorer. You can
then specify the icons name from the senders side. More details of the
AAR anatomy here.
If you just change the extension to aar, it won't compile.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':unityLibrary:compileReleaseJavaWithJavac'.
> Could not resolve all files for configuration ':unityLibrary:releaseCompileClasspath'.
> Failed to transform firebase_notification_icon-.aar (:firebase_notification_icon:) to match attributes {artifactType=android-classes-jar, org.gradle.status=integration, org.gradle.usage=java-api}.
> Execution failed for AarToClassTransform: C:\...\.gradle\caches\transforms-2\files-2.1\ea6ac2b3d0993f0958d52cbbdfbd76ea\jetified-firebase_notification_icon.aar.
> entry
AAR-file must be created in Android Studio. Since it must contain a number of required files such as AndroidManifest.xml, classes.jar, etc.