Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manifest merger failed targeting Android 12

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?

like image 411
SVP Avatar asked May 22 '21 21:05

SVP


People also ask

How do I fix error manifest merger failed?

The initial process would be to open the manifest application known as the AndroidManifest. xml and then click on the Merged Manifest tab below your edit pane. Following which, Click on the merged manifest option. An Error would be visible at the right column and then one must try to solve the error.

How do I find my merged manifest Android?

Inspect the merged manifest and find conflicts Even before you build your app, you can see a preview of what your merged manifest looks by opening your AndroidManifest. xml file in Android Studio, and then clicking the Merged Manifest tab at the bottom of the editor.

What is manifest folder in Android Studio?

Manifests folder contains AndroidManifest. xml for our creating the android application. This file contains information about our application such as the Android version, metadata, states package for Kotlin file, and other application components. It acts as an intermediator between android OS and our application.


Video Answer


4 Answers

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.

like image 158
SVP Avatar answered Oct 19 '22 17:10

SVP


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

like image 8
MarlonDSC Avatar answered Oct 19 '22 19:10

MarlonDSC


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.

like image 5
Ankit Avatar answered Oct 19 '22 18:10

Ankit


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"
like image 2
Hardik Hirpara Avatar answered Oct 19 '22 18:10

Hardik Hirpara