1

I'm having this error on a Jetpack Compose project. Manifest merger failed : 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

It all started when I added this dependency implementation 'com.shakebugs:shake:14.4.0' I followed the setup here https://www.shakebugs.com/docs/android/setup

Here is my Manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.uticodes.compose_otp_input_field">

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Compose_otp_input_field">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.Compose_otp_input_field.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest> ```

App class
```class App : Application() {

    override fun onCreate() {
        super.onCreate()
        Shake.getReportConfiguration().isInvokeShakeOnShakeDeviceEvent = true
        Shake.start(this, "clientId", "clientScret")
    }
} ```

My compileSdk ```compileSdk 31 ``` , ```minSdk 21``` , ``` kotlinCompilerVersion '1.5.21'``` , ```compose_version = '1.0.1' ``` , ```gradle:7.0.1 ```
  • Check your merged manifest to see what other activities are added by libraries. Make sure that you are on the latest version of those libraries. And consider using manifest merger rules to add the `android:exported` flag via your own manifest. – CommonsWare Sep 15 '21 at 21:00
  • BTW, my apologies -- the error appears to be for a service, not an activity, given your question title. – CommonsWare Sep 15 '21 at 21:22
  • Yes, the error is for a service but I don't have any service class on the app – Teebeh Eteem Sep 16 '21 at 15:50
  • Updating my original comment: check your merged manifest to see what other services are added by libraries. Make sure that you are on the latest version of those libraries. And consider using manifest merger rules to add the `android:exported` flag via your own manifest. – CommonsWare Sep 16 '21 at 16:05

1 Answers1

1

When you are targeting API level 31, all activities with intent-filters, services, receivers, providers must explicitly specify whether they are exported or not in AndroidManifest.xml

android:exported="true"

Also this issue can be happening because some of your dependencies (3rd party libs) do not have this attribute set. In order to fix that you should override exported attribute for them:

<activity android:name="name_of_the_activity_inside_library">
    android:exported="false|true"
    tools:node="merge" />

You will be able to remove this once the libs your are using adds exported attribute.

Note: the manifest merge task fails without generating the manifest when targeting Android 12 and you can't event find what causing the issue, so my advise is to compile the app using a targetSdk 30 and find which components have this issue in the generated manifest.

c-an
  • 3,543
  • 5
  • 35
  • 82
asamoylenko
  • 2,107
  • 2
  • 18
  • 13
  • 2
    androidx.test:core library version 1.3.0. Upgrading to version 1.4.0 fixed the issue. – faizy Oct 26 '21 at 18:09
  • @faizy Upgrading `androidx.test:core` solved the issue. Why not post it in an answer :) – hqzxzwb Dec 15 '21 at 03:18
  • In my case the error is pointing to a class that is not an activity. It doesn't make much sense. Is there a way to fix that? Also, is there a place I can find that merged manifest? – Machado Apr 19 '23 at 10:19