Home > Enterprise >  Flutter: Targeting S (version 31 and above) requires that an explicit value for android:exported be
Flutter: Targeting S (version 31 and above) requires that an explicit value for android:exported be

Time:08-16

But I set it:

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="MY LABEL">
        <activity
            android:name=".MainActivity"
            android:exported="true"
             ...

Invalidated caches and restarted android studio. Still if I try to start the app on emulator with Android 12, it throws this error:

Error: ADB exited with exit code 1
Performing Streamed Install

adb: failed to install E:\mobileapp\build\app\outputs\flutter-apk\app.apk: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl279592420.tmp/base.apk (at Binary XML file line #186): com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver: Targeting S  (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]
Error launching application on sdk gphone64 x86 64.

This is my AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mymobile">

    <queries>
        <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>

    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="MY LABEL">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            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" />
            <meta-data
                android:name="com.google.firebase.messaging.default_notification_channel_id"
                android:value="my_high_importance_channel" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </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>

I have only one activity, no service. So no idea what is the problem while there is a problem. I did not find anything extra. Everything I found, is that set the boolean flag to true and it should work but obviously it does not.

The fix:

...
</activity>
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
            android:exported="true">
        </receiver>

See here: https://www.youtube.com/watch?v=fma_umbAe6A

CodePudding user response:

The problem lies with the flutter_local_notifications plugin that you are using. Updating that to the latest version should solve it.

See their readme also at https://pub.dev/packages/flutter_local_notifications#-android-setup :

Before proceeding, please make sure you are using the latest version of the plugin. The reason for this is that since version 3.0.1 4, the amount of setup needed has been reduced. Previously, applications needed changes done to the AndroidManifest.xml file and there was a bit more setup needed for release builds. If for some reason, your application still needs to use an older version of the plugin then make use of the release tags to refer back to older versions of readme.

If you can't or don't want to update it you need to add some lines to your manifest.

Maybe you can try to add what the person in this video does:

https://www.youtube.com/watch?v=fma_umbAe6A

If it doesn't work maybe find the readme of your version here for example and follow the instructions there https://pub.dev/packages/flutter_local_notifications/versions

  • Related