You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without the 'an

Viewed 38604

Issue: You uploaded an APK or Android App Bundle which has an activity, activity alias, service, or broadcast receiver with intent filter, but without the '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

My AndroidManifest.xml file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.c4life.guardianangel">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<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
   tools:replace="android:label"
   android:label="GA"
   android:exported="true"
   android:icon="@mipmap/ic_launcher">
   <meta-data android:name="com.google.android.geo.API_KEY"
       android:value="[insert API key here]"/>
    <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"
          />
        <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>
   <service android:name="changjoopark.com.flutter_foreground_plugin.FlutterForegroundService" android:exported="false"/>
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />


</application>

<uses-sdk
    android:targetSdkVersion="30"
    tools:overrideLibrary="changjoopark.com.flutter_foreground_plugin" />
12 Answers

Accord to google new policy 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:true attribute for these app components.

Inside main manifest file make sure every single tag like ( activity , services , receiver) must have set android:exported property to true or false.

So In main manifest file check all the activities, services , receiver that can use intent-filter which are without android:exported tag. Add android:exported="true" or android:exported="false" for these tags.

You might ask when do I need to add android:exported="true" or android:exported="false" to the activities, services, or broadcast receivers that use intent filters. If the app component includes the LAUNCHER category, set android:exported to true otherwise set android:exported to false.

If adding android:exported in main manifest file not works for you follow below steps :

  • open AndroidManifest.xml file and in bottom select Merged Manifest. like this : enter image description here

  • if you not able to preview Merged Manifest then in your build.gradle file set compileSdkVersion 30 and targetSdkVersion 30 and sync your project and now try to open merged manifest again I hope this time you will have proper preview of merged manifest. but if there is no preview don't worry you can still navigate to individual manifest files from different third party libraries you have used in your project.

  • Note : also check individual third party library manifest files if there is any activity , service or receiver using then you have to override same activity , service or receiver in your main manifest file with android:exported property.

For Example in my case I have defined android:exported for each and every activity , service or receiver in my main manifest file but in my project I was using Razorpay dependency so in the manifest of razorpay I found that there is an activity and receiver which are using property without android:exported so I declared them in my main manifest files. as shown below :

 <activity
        android:name="com.razorpay.CheckoutActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:theme="@style/CheckoutTheme"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <data
                android:host="rzp.io"
                android:scheme="io.rzp" />
        </intent-filter>
    </activity>

    <receiver android:name="com.razorpay.RzpTokenReceiver"
        android:exported="true"
        android:permission="android.permission.INTERNET">
        <intent-filter>
            <action android:name="rzp.device_token.share" />
        </intent-filter>
    </receiver>

Note : in your case you may have to go through more files and check activity , services and mention them in your main manifest file.

  • also after doing all this you can changes back to targetSdkVersion 31 and compileSdkVersion 31 in your build.gradle file.

In my case, I just add this line to my manifest:

android:exported="true"

enter image description here

I finally fixed this issue

1: install emulator with android v 12

2: run your app the compailer will tell you what service/reciver...etc casued the issue

now you have to add it to your manifist and add the android:exported="true" to it

in my case the prblem was with the local notifcation package i got the message to fix this receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver so i added to my manifist out side the main activity

 <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
 android:exported="true">
       <intent-filter>
           <action android:name="android.intent.action.BOOT_COMPLETED"/>
           <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
       </intent-filter>
   </receiver>

and it worked as intended

The "exported" attribute describes whether or not someone else can be allowed to use it.

So if you have "exported=false" on an Activity, no other app, or even the Android system itself, can launch it. Only you can do that, from inside your own application.

So settings "exported=false" on the Activity marked as the LAUNCHER Activity would basically tell the system that it cant launch your application, ever.

if use targetSdkVersion=31

    package="com.name.app"><!-- Channnge your package -->
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="https" />
        </intent>
        <intent>
            <action android:name="android.intent.action.DIAL" />
            <data android:scheme="tel" />
        </intent>
        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="*/*" />
        </intent>
    </queries>
   <application
        android:label="Tut Elimi"
        android:icon="@mipmap/ic_launcher">
       <service android:name="com.example.app.backgroundService"
           android:exported="true">
           <intent-filter>
               <action android:name="com.example.app.START_BACKGROUND" />
           </intent-filter>
       </service>
       <meta-data
           android:name="com.google.android.gms.ads.APPLICATION_ID"
           android:value=""/>
        <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">

            <!-- 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="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/splash"
                />
            <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>
            <!-- 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. -->
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
       <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"
           android:exported="true">
           <intent-filter>
               <action android:name="android.intent.action.BOOT_COMPLETED"/>
               <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
           </intent-filter>
       </receiver>
       <service
           android:name="com.name.app.BackgroundService"
           android:enabled="true"
           android:exported="true" />
       <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>  

</manifest>  ````   

If you are not using any other project then update all library latest versions because some old library AndroidManifest.xml not added android: exported in activities, services, or broadcast receivers

By just adding exported:true to your Android manifest activity did not solve my issue. You have to

  • open project in Android studio
  • Open Androidmanifest.xml
  • At the bottom select merged manifest

enter image description here

  • Now ensure that you add exported to true wherever stated and fix those warnings specified on the line (in blue) and tapping blue text does not take you to one of these tags Services, activity, receiver in above step then look for the library for which the merge error exist

e.g a merge error here shows issue in flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

enter image description here

So go to the manifest of that specific library which is listed in blue above the error, where you can add exported to true.(this will also resolve the merge error)

enter image description here

Add exported to true in services tag

enter image description here

Video demo here: https://www.youtube.com/watch?v=hy0J8MNnE6g

Adding the line android:exported="true" to my Manifes

Need to add android:exported="true" to all components which has an intent-filter.

See where you need to add it you can opening Merged Manifest file.

enter image description here

enter image description here

enter image description here

enter image description here

If your Android Studio don't show the Merged Manifest tab, you can figure out what is the problem by searching on the merged AndroidManifest.xml file.

To me it was on: \build\app\intermediates\merged_manifests\release\AndroidManifest.xml

And my problem was the ScheduledNotificationBootReceiver:

Add this to your Manifest:

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

If you are flutter developer and unable to find Merged Manifest tab, follow th e steps:

  1. Open Project in Android Studio.
  2. Navigate to main AndroidManifest.xml.
  3. Navigation
  4. Wait for Project Loading Wait for Project
  5. Here it is... Found

Just change
build.gradle -> defaultConfig

targetSdkVersion="31"

to

targetSdkVersion="30"

work normal for me.

Related