India
India

Reputation: 423

Android Studio, updating build.gradle TargetSdkVersion 31 issues

We are using targetSdkVersion 30, I am trying to update it to 31

When I set targetSdkVersion to 31, I am unable to run/compile the app because it is failing build error in manifest.xml saying

android:exported needs to be explicitly specified for . 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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. src/main/AndroidManifest.xml

I checked my manifest file, I added android:exported = true/false for every activity , receiver!

I do not have issue if I set targeted SDK version to 30, but 31 and I am sure I added android:exported to all applicable components in manifest

please help me

Upvotes: 4

Views: 16349

Answers (4)

Dankyi Anno Kwaku
Dankyi Anno Kwaku

Reputation: 1293

Chances are, it's the libraries in your gradle file. This is how I solved it.

  1. Comment out one library in your gradle file, clean project and rebuild project.
  2. If it shows the same error, uncomment it, and repeat step 1.
  3. Do this for each library and eventually, you will find that the error will change or the build will be successful.
  4. When that happens, that last library that you commented is the problem. Try updating that library or using a different one.

Upvotes: 0

Roel Leal
Roel Leal

Reputation: 677

  1. In windows/user/.gradle

Delete .gradle, delete the folder

  1. Reopen Android studio and change in project structure/grandle Change the version of the grandle

  2. In the project build.gradle update the dependencies

Upvotes: 0

Black Hawk
Black Hawk

Reputation: 1

For your flutter project, Go to: *your_project*/android/app/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" //add this line
    package="com.example.***your_app_name***">

Search for the entry of the type activity within application in the same AndroidManifest.xml file

        <application
            android:name="${applicationName}"
            ...
            ...
            
    
            <meta-data 
              ...
              ... />
    
            <meta-data
              ...
              ... />
    
            <activity
                android:name=".MainActivity"
                android:exported="true"    //add this line
                tools:node="merge"         //add this line
                android:launchMode=
                ...
                ...
                ...

Upvotes: 0

Sujal Kumar
Sujal Kumar

Reputation: 1164

Update all libraries in build.gradle file if haven't already. There's a big chance that one of them is causing this. If this isn't the case, you would have to manually check the Merged Manifest as mentioned by @DarShan. It happened to me few days ago as well.

Upvotes: 7

Related Questions