1

I am getting manifest merger failed error. I have tried most suggested way to fix below error with dependency but unable to resolve.

Below is my Gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.plainnotes"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    // additional libraries
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
    implementation 'androidx.room:room-runtime:2.1.0-alpha03'
    annotationProcessor "androidx.room:room-compiler:2.1.0-alpha03"
    implementation 'com.jakewharton:butterknife:10.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
}

This is the Error message that I received

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-22:19 to override.
Molly
  • 1,887
  • 3
  • 17
  • 34
Code Lover
  • 8,099
  • 20
  • 84
  • 154
  • I think you're mixing new androidx and older version of android support library. – ZeeShaN AbbAs Jan 23 '19 at 09:15
  • Probably you are right but when I removed `androidx` and kept `butterknife` it is still giving the same error – Code Lover Jan 23 '19 at 09:16
  • @CodeLover By the way you can check the issue in merged manifest tag. Open your manifest file and the bottom left you will see text, merged manifest. Click it and it will tell you the issue and the possible fix too :) – Umair Jan 23 '19 at 09:33

3 Answers3

2

I had a similar problem. Two lines in gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

and add this in manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools"
package="your.package.uri">

<application
    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"
    tools:replace="android:appComponentFactory"
    android:appComponentFactory="androidx">
2

It because you are using a different library for android. Made refactor to AndroidX packages for all library

With this

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

// additional libraries
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
implementation 'androidx.room:room-runtime:2.1.0-alpha03'
annotationProcessor "androidx.room:room-compiler:2.1.0-alpha03"
implementation 'com.jakewharton:butterknife:10.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'

to this

//Android support libraries.
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'

    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2' 

As of Support Library and AndroidX Library are diffrent one. So use only one type of library.

Ankit Tale
  • 1,924
  • 4
  • 17
  • 30
  • This is perfect solution. However, I would like to know where I can check all `androidx` dependency versions and other details. – Code Lover Jan 23 '19 at 09:22
  • 1
    I found another way to migrate.. `Android Studio > Refractor > Migrate to AndroidX...` – Code Lover Jan 23 '19 at 09:33
0

You are mixing new androidx package with older version of android support library. You can find a guide and new androidx package on following link https://developer.android.com/jetpack/androidx/migrate

ZeeShaN AbbAs
  • 1,365
  • 2
  • 15
  • 31