skip to Main Content

So, I am a beginner into Android and Kotlin. I just began learning. While I was experimenting with Intent today, I incurred an error.

Manifest merger failed with multiple errors, see logs

I found some solutions here and tried to implement them, but it did not work.

This is my build.gradle :

`

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 33

    defaultConfig {
        applicationId "com.example.chattery"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleDependency
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.firebase:firebase-auth:21.1.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.firebase:firebase-database:20.1.0'
    implementation 'com.google.firebase:firebase-storage:20.1.0'
    implementation 'com.google.firebase:firebase-messaging:23.1.0'
    implementation 'com.google.firebase:firebase-auth-ktx:21.1.0'
    implementation 'com.google.firebase:firebase-database-ktx:20.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'com.mikhaellopez:circularimageview:4.2.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.firebaseui:firebase-ui-database:4.3.0'
    implementation 'id.zelory:compressor:3.0.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
    implementation 'com.squareup.okhttp:okhttp:2.7.5'
}

`

This is my AndroidManifest :

`

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name=".commons.ChatteryApplication"
        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/AppTheme">
        <activity android:name=".ui.activities.ChatActivity"
            android:theme="@style/ActivityActionBarTheme"
            android:parentActivityName=".ui.activities.MainActivity"/>
        <activity
            android:name=".ui.activities.SettingsActivity"
            android:parentActivityName=".ui.activities.MainActivity" />
        <activity android:name=".ui.activities.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ui.activities.WelcomeActivity"
            android:screenOrientation="portrait"
            android:theme="@style/LoginTheme" />
        <activity
            android:name=".ui.activities.SignUpActivity"
            android:parentActivityName=".ui.activities.WelcomeActivity"
            android:theme="@style/ActivityActionBarTheme" />
        <activity
            android:name=".ui.activities.LoginActivity"
            android:parentActivityName=".ui.activities.WelcomeActivity"
            android:theme="@style/ActivityActionBarTheme" />
        <activity
            android:name=".ui.activities.UsersActivity"
            android:parentActivityName=".ui.activities.SettingsActivity"
            android:theme="@style/ActivityActionBarTheme" />
        <activity android:name=".ui.activities.ProfileActivity">
            <intent-filter>
                <action android:name="com.example.chattery.NOTIFICATION_TARGET" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
            android:theme="@style/Base.Theme.AppCompat" />

        <service
            android:name=".firebase.MessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
    </application>

</manifest>

`

This is my Merging Errors :

Merging Errors: 
Error: android:exported needs to be explicitly specified for element <activity#com.example.chattery.ui.activities.MainActivity>. 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. Chattery.app main manifest (this file), line 23 Error: android:exported needs to be explicitly specified for element <activity#com.example.chattery.ui.activities.ProfileActivity>. 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. Chattery.app main manifest (this file), line 46 

This is my first week with coding, I am sorry if this is a really silly thing. I am really new to this and did not find any other place to ask. Sorry if I broke any rules

2

Answers


  1. Error Message

    As the error message suggests you might want to add android:exported to your activity definition. It also informs you about the fact, that this is only the case for targetSdk >= 31. So another solution would be to lower you targetSdk. But that would come with some feature tradeoffs. I wouldn’t recommend that.

    Solution 1 (Recommended)

    According to this statement here. Google suggests not setting this property unnecessarily to true

    So the simplest solution would be to change this in your AndroidManifest.xml:

    <activity android:name=".ui.activities.MainActivity">
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
    </activity>
    

    To this:

    <activity android:name=".ui.activities.MainActivity" android:exported="false">
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
    </activity>
    

    Notice the added android:exported attribute.

    Solution 2 (Not Recommended)

    In your module level gradle.build you have somewhere at the top the property targetSdk. Change the value to something lower than 31 eg. 30 which corresponds to Android 11. Mind that you need to download the required target sdk via the sdk manager. Otherwise you won’t be able to compile your app anymore

    Login or Signup to reply.
  2. androidTestImplementation ‘androidx.test.ext:junit:1.1.3’

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search