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

FlutterAndroid 12

Flutter Problem Overview


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

Flutter Solutions


Solution 1 - Flutter

Android 12 require you to add a piece of code to your main activity

  1. Go to your project folder and open AndroidManifest.xml file

  2. Add the below code in activity

    android:exported="true"

  3. Example

    <activity
         android:name=".MainActivity"
         android:exported="true"
         android:launchMode="singleTop"
         android:theme="@style/LaunchTheme"
     </activity>
    

Solution 2 - Flutter

In AndroidManifest.xml add android:exported="true":

<manifest ...>
  <application ...>
    <activity
        android:exported="true"

Solution 3 - Flutter

Thanks @rahul-kavati.

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

Solution 4 - Flutter

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>

Solution 5 - Flutter

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

Solution 6 - Flutter

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

Solution 7 - Flutter

Yes,in AndroidManifest.xml

 <activity
    android:exported="true" //here it is
    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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRahul KavatiView Question on Stackoverflow
Solution 1 - FlutterRahul KavatiView Answer on Stackoverflow
Solution 2 - FlutteredalvbView Answer on Stackoverflow
Solution 3 - FlutterAndriiView Answer on Stackoverflow
Solution 4 - FlutterAlex BolotnikoffView Answer on Stackoverflow
Solution 5 - FlutterlinuxiasView Answer on Stackoverflow
Solution 6 - FluttertaxidealsView Answer on Stackoverflow
Solution 7 - FlutterBogdan ZagrebaView Answer on Stackoverflow