129

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

Rahul Kavati
  • 3,800
  • 3
  • 7
  • 15

9 Answers9

221

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"

Reference:

   <activity
        android:name=".MainActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme">
    </activity>
Rahul Kavati
  • 3,800
  • 3
  • 7
  • 15
  • 4
    This property has to be set within the tag. – madlick71 Jan 06 '22 at 08:35
  • Can you be more specific about where it has to be added? – Christian Jan 25 '22 at 13:23
  • add in this file: android/app/src/main/AndroidManifest.xml – Rahul Kavati Jan 27 '22 at 09:20
  • That seems to solve the problem, but still that answer needs clarification as of what does that parameter means and why set to true and not false for example. – Fernando Rocha Feb 15 '22 at 14:58
  • Clear information is mentioned in the following document. link : https://developer.android.com/guide/topics/manifest/receiver-element.html?hl=es – Rahul Kavati Feb 17 '22 at 18:22
  • 8
    Why is it needed? What does `android:exported="true"` mean / do? – instanceof Feb 23 '22 at 15:17
  • 2
    @instanceof More info about that attribute can be found at https://medium.com/androiddevelopers/lets-be-explicit-about-our-intent-filters-c5dbe2dbdce0 – Michael Rumpler Feb 24 '22 at 15:50
  • 57
    Just to be clear, this answer is NOT GOOD. You need this attribute on EACH activity with an intent filter and on EACH service also. Again, thanks Android for those useless updates that breaks millions of deployments around the world! You're champions! – Nicolas Belley Mar 03 '22 at 16:05
  • 3
    Also check your dependencies for updates. I my case the local_notifications plugin caused the error because the old plugin version did not set the exported property. – julienduchow Apr 11 '22 at 10:52
  • 3
    I added `android:exported="true"` but its still giving the same issue – Zeeshan Ahmad Khalil Aug 22 '22 at 17:43
  • 1
    @NicolasBelley +1 Also, all `receiver`s with `intent-filters` must also include this property. So to sum up, `android:exported="true"` or `"false"` must be added to all `receiver`s, `service`s, and `activity` tags with `intent-filters` inside them. – sj_959 Sep 15 '22 at 06:11
  • works, I had to put it on all my activities, not just MainActivity – pjaaar Feb 02 '23 at 10:01
  • I'm pretty sure you have a extra dangling closing '>' at the end of this: android:theme="@style/LaunchTheme"> – Steve3p0 Feb 02 '23 at 13:29
33

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

<manifest ...>
  <application ...>
    <activity
        android:exported="true"
Shurvir Mori
  • 2,288
  • 1
  • 17
  • 29
edalvb
  • 581
  • 6
  • 7
  • 5
    This solved my issue when building in flutter, by placing `android:exported="true"` in app/src/main/AndroidManifest.xml – redsd Jan 30 '22 at 08:53
13

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

linuxias
  • 306
  • 2
  • 10
7

Thanks @rahul-kavati.

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

Andrii
  • 1,081
  • 1
  • 11
  • 24
  • When I add this I get Error : System.InvalidOperationException: Duplicate attribute yet I've searched all my code and Exported is only defined once. Any ideas? – Christine Mar 07 '22 at 18:06
  • Maybe you have it more than once? – Andrii Mar 08 '22 at 23:02
  • 1
    it's a xamarin android bug, https://github.com/xamarin/xamarin-android/issues/6463. The fix is only for VS22 and I'm still running VS19 – Christine Mar 10 '22 at 00:14
4

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

nefen
  • 767
  • 7
  • 6
3

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

linchuan
  • 39
  • 2
2

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>
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 07 '22 at 21:50
1

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

Phil Seeman
  • 397
  • 3
  • 11
taxideals
  • 37
  • 5
0

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

  1. Open platforms/android/android.json
  2. 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

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