Manifest merger failed targeting Android 12 [duplicate]
Asked Answered
C

8

79

Using Android Studio 4.2.1, after changing sdk target to Android 12 in my build.gradle file, I am getting a Manifest merger failed with multiple errors, see logs error.

The errors shown in the Merged Manifest tab are as follows:

Merging Errors: 
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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 
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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. My_App.app main manifest (this file) 

However the android:exported tag is already applied in my AndroidManifest.xml file. I only have one activity. No services or broadcast receivers. See below:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.mydomain.myapp">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:name="com.mydomain.myapp.MyApplication"
        android:allowBackup="false"
        tools:replace="allowBackup"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name="com.mydomain.myapp.ui.MainActivity"
            android:exported="true">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

</manifest>

My build.gradle(:app) file:

android {
    compileSdkVersion("android-S")
    buildToolsVersion "30.0.3"

    defaultConfig {
        ...
        minSdkVersion 23
        targetSdkVersion("S")
        ...
}

Any idea how I could resolve this issue?

Crabstick answered 22/5, 2021 at 21:57 Comment(11)
Are you sure the manifest shown in the Merged Manifest tab does not contain additional components? Libraries can contribute activities, services, and receivers.Crook
@Crook The issue seems to indeed be caused by third-party libraries missing the android:exported tag. The Merged Manifest tab was showing empty ("Nothing to show") because the merge failed so I had to rebuild with a target below Android 12 to investigate. Thanks!Crabstick
That's interesting and feels like a bug/limitation in Studio. Even if it cannot provide all the features of the normal Merged Manifest tab, it should at least show what the merged manifest contains, just for scenarios like this one.Crook
@Crook Agreed. It would also be nice if the errors in the right side panel could point to which component caused the error. To add to the confusion, at the top of the right side panel, it read : "Other Manifest Files (Included in merge, but did not contribute any elements)" which I interpreted as "other manifest files are not the source of the error.Crabstick
If you do not mind my asking... what were the libraries that gave you these results? I would like to try to reproduce the problem and perhaps file a bug report (if you have not done so already). Thanks!Crook
@Crook I did already create some PRs for the libraries!Crabstick
Sorry, I meant I was looking to file a bug report against Studio, for not showing the merged manifest due to the Lint messages.Crook
Let us continue this discussion in chat.Crabstick
@Crook What about 3rd party libraries that are required by a project, but are not being updated to test against Android 12 by specifying the android:exported flag? I'm working on a large framework with a lot of dependencies and would like to test against Android 12. I know some of the libs won't be updating the manifests anytime soon. Should we look at the failed manifest merger and explicitly override all the intents that have no yet set their exported flag?Mountie
@dell116: "Should we look at the failed manifest merger and explicitly override all the intents that have no yet set their exported flag?" -- most likely, yes. You should be able to add entries to your own manifest, with the same tag and android:name values, setting android:exported="true", in your app module's manifest.Crook
I recently migrated my apps to android 12, and yes i faced all of these issues, here is the migration journey solution : medium.com/native-mobile-bits/…Publisher
C
174

The issue was caused by 3 activities missing the android:exported attribute in the androidx.test:core library version 1.3.0. Upgrading to version 1.4.0-beta01 fixed the issue.

If you are getting errors after targeting Android 12, the easiest way to debug this is to:

  • downgrade to a prior sdk version
  • rebuild project
  • after a successful build, open your project's AndroidManifest.xml.
  • at the bottom of the window, click on the Merged Manifest tab
  • look for any <activity> that includes an <intent-filter> tag and is missing the android:exported attribute

If you want to make sure these activities are the issue, add them directly to your project's AndroidManifest.xml file with the missing android:exported attribute added and try rebuilding the project.

So if <activity android:name="com.domain.ProblemActivity"> is missing the android:exported attribute, add it to your AndroidManifest.xml file like so:

<activity 
 android:name="com.domain.ProblemActivity"
 android:exported="true" >

Rebuild targeting Android 12 and if it works, then you found the bug!

Thanks @MikePenz for pointing me in the right direction.

Crabstick answered 24/5, 2021 at 7:24 Comment(13)
Thanks for the tip. I was able to find out the activity that was missing the exported attribute. It was indeed an activity from a third party library that got automatically added to the manifest.Vivienne
These steps definitely helped. I forgot that using the <nav-graph> from the Navigation Component also generates the <intent-filter> tag. You will need to add the exported property to those activities as well.Kalong
When I edit the manifest's third party libs to add the export it won't save the file any idea why? do I need to include manually all the activities to my manifest?Vagus
@Vagus are you trying to edit the libraries' manifest files? Because I don't think you can do that. Someone correct me if I'm wrong. Then you have 2 options: add all the problem activities to your app's manifest file, or contact the authors of the libraries to let them know they should add the attribute to avoid any issue with Android 12.Crabstick
@tb_car_04 I'm on a big project, I had no choice but to add 50 activities to my manifest file, that not the best solution. the best is to wait for the authors of the libs to update their manifest for Android 12.Vagus
Not working in my project. I have no activities with intent-filter without exported attribute, but still I have this compilation error! How can I find where exactly is the activity without exported attribute?Classmate
I was able to figure out what was causing the issue in my project by running gradlew processDebugAndroidTestManifest --debug and scrolling up to where the "Apps targeting Android 12 and higher..." text was being shown. In my case the INFO line above it was showing merging espresso which needed to be updated to 3.4.0. Another thing that needed to be updated was WorkManager.Preservative
if you still failed after add it to <activity> , you also need to add android:exported to your receiver https://mcmap.net/q/99654/-android-studio-error-quot-manifest-merger-failed-apps-targeting-android-12-quot-duplicateKwapong
In my case "androidx.test.ext:junit:1.1.1' was causing this, removing that dependency solved it. Thanks for this answer though, it helped me to look into my dependency list!Lemmons
I experienced this issue when trying to run tests during (navigation/testing in compose) codelabs. As @Preservative said, I ran ./gradlew processDebugAndroidTestManifest --debug. For me, it was espresso-contrib and espresso-core. Pressing ctrl+alt+shift+s, selecting Dependencies, and then selecting the highest available version (which at the time of this, was 3.5.0-alpha03), resolved the problem after following up with Apply and Ok.Merriment
I can't understand why we can't easily find a manifest file has issueGoltz
@Crabstick issue resolved but. in android 12 the notificaion is not openingPocketknife
This fixed my issue! I saw that it was a library that had a <service> tag without "android:exported", I updated it and it was solvedKennel
P
9

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 attribute for these app components. In order to solve this we need to follow these steps:

  1. We need to locate the AndroidManifest.xml in the main folder.

android>app>src>main>AndroidManifest.xml

enter image description here

  1. We have to add android:exported="" and set a boolean value inside these quotation marks. Now 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. In most other cases, set android:exported to false.

  2. This is an example of how it should look like in your AndroidManifest.xml

<service android:name="com.example.app.backgroundService"
         android:exported="false">
    <intent-filter>
        <action android:name="com.example.app.START_BACKGROUND" />
    </intent-filter>
</service>

You can check out more info about this topic by following this link:

Safer component exporting for Android 12

Polygraph answered 18/11, 2021 at 14:25 Comment(0)
L
6

If you upgrade your android studio to Bumblebee 2021.1.1. The below changes are required to do: Step 1: Your targetSdkVersion must be 30 or higher Step 2: Update your appcompat library to implementation 'androidx.appcompat:appcompat:1.4.1'

Step 3: In the AndroidManifest file add android:exported = true to your activity launcher.

Leukemia answered 2/3, 2022 at 12:10 Comment(0)
F
3

I had my Activity setup correctly with 'exported=true' and still had the following issue:

Installation failed due to [...] androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present

So I came across this Github post, which could explain why this happens, and applied the workaround yogurtearl suggests and it worked for me.

https://github.com/android/android-test/issues/832

It basically goes like this:

As a workaround, putting this in the app/src/debug/AndroidManifest.xml it will force the these to launch in the same test process.

    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
        android:exported="true"
        android:theme="@android:style/Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
        android:exported="true"
        android:theme="@android:style/Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
        android:exported="true"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>

And added the 'exported=true' to them.

Fulmar answered 20/1, 2022 at 15:11 Comment(0)
I
2

I had this issue, find it by:

  • if there's any activity, service, receiver, or provider that does not have exported attribute in your AndroidManifest file then add the below attribute in that activity, service, receiver, or provider

android:exported="false or true"
Infusive answered 1/10, 2021 at 7:5 Comment(0)
A
0

Don't forget to put it also into service tag

    <service
        android:name=".service.MyIME"
        android:exported="true"
        android:permission="android.permission.BIND_INPUT_METHOD">
        <meta-data
            android:name="android.view.im"
            android:resource="@xml/method" />

        <intent-filter>
            <action android:name="android.view.InputMethod" />
        </intent-filter>
    </service>
Aubade answered 6/11, 2021 at 2:26 Comment(0)
H
0

If you're using DexGuard you should update to the latest version which is 9.2.11 (19-01-2022) at the moment.

Quote from the release notes:

Add default configuration for keeping the exported attribute as required by applications targeting Android 12.

Hildegardehildesheim answered 21/1, 2022 at 15:23 Comment(0)
B
0

As specified in the following link- https://developer.android.com/about/versions/12/behavior-changes-12#exported ,the components of android that use intent filters must explicitly define component exporting, failing to which your app can't be installed on a device that runs on Android 12 or higher. The app components include activities, services, broadcast receivers and content providers.

If the app component includes the LAUNCHER category, set android:exported to true. In most other cases, set android:exported to false.

Even after setting the android:exported tag, if you are facing the Manifest Merger failed issue, then check all the libraries that you are using in your app. Open the external libraries in the project view of the Android Studio and try to check all the manifests files of the libraries that you have included in your project. Any one of those libraries might have not updated according to Android 12. So if you find any manifest file of the library with exported tag missing, try to edit the file and add this tag there too. Hope that could help in removing Manifest Merger Error.

Bullins answered 31/5, 2022 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.