77

When I'm building Gradle with androidx I get the following error. Please help me to solve this issue.

Error Message: 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).

Manifest:

<?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.kanwarpreet.dealmybook"> <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"> <activity android:name=".activities.SplashActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".activities.LoginActivity" /> <activity android:name=".activities.RegisterActivity" /> <activity android:name=".activities.HomeActivity" android:label="@string/title_activity_home" android:theme="@style/AppTheme.NoActionBar" /> <activity android:name=".activities.BookDetailsActivity" android:label="@string/title_activity_book_details" android:theme="@style/AppTheme.NoActionBar"/> <activity android:name=".activities.AddBookActivity" /> </application> </manifest> 

Build.Gradle:

apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.kanwarpreet.dealmybook" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.google.android.material:material:1.0.0' implementation 'com.jakewharton:butterknife:10.1.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.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' } 
1
  • 1
    Try my solution. Remove all appcompat number verisons from gradle and imports from code, replace them with androidx equivalents and then sync gradle. Commented Mar 18, 2019 at 10:02

14 Answers 14

109

Put these flags in your gradle.properties

android.enableJetifier=true android.useAndroidX=true 
Sign up to request clarification or add additional context in comments.

Comments

75

After hours of struggling, I solved it by including the following within app/build.gradle:

android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } 

Put these flags in your gradle.properties

android.enableJetifier=true android.useAndroidX=true 

Changes in build.gradle:

implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.google.android.material:material:1.1.0-alpha04' 

Refer to: https://developer.android.com/jetpack/androidx/migrate

4 Comments

compileOptions solved this for me after a day of Struggling
It worked but after adding these two lines in application tag of manifest i.e. tools:replace="android:appComponentFactory" android:appComponentFactory="androidx"
But there is a error in V7 imports in activity, what to do?
Thanks. The error was with this=android.enableJetifier=true is wasn't resent
37

Reason of this error-

Because after upgrade, androidx.core:core is accessed somewhere, when your project is still not using androidx. So classes like CoreComponentFactory and many others are now found at two places - androidx.core:core and com.android.support:support-compat. That's why this error occured.

What is solution?

You should migrate to AndroidX. If you don't know about AndroidX. Please read What is AndroidX?

How to migrate your project

After Android Studio 3.2 (September 2018), there is direct option to migrate existing project to AndroidX. This refract all packages automatically.

Before you migrate, it is strongly recommended to backup your project.

Existing project

  • Android Studio > Refactor Menu > Migrate to AndroidX...
  • It will analysis and will open Refractor window in bottom. Accept changes to be done.

image

New project

Put these flags in your gradle.properties

android.enableJetifier=true android.useAndroidX=true 

Check @Library mappings for equal AndroidX package.

Check @Official page of Migrate to AndroidX

Comments

6

Error explicitly says-

[com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0]

AndroidX is the latest support library from Google. It contains all previous components from all older appcompat versions. Do NOT use appcompat-v-any number. Instead, use a similar component from AndroidX libraries. Remove the numbered support libraries from your Gradle and your code wherever it is imported. Then sync your gradle.

Component similarity table can be found here. Also, follow the steps mentioned in Migrating to AndroidX.

Again, stop using any previous appcompat numbered versions. There's only AndroidX now.

Hope this helps.

5 Comments

Remove the numbered support libraries from your Gradle and your code not make sense because the Migrate to AndroidX is complete another process.
Op has mentioned "...when I building Gradle with androidx " When you use AndroidX one should use all of it otherwise there will be similarity conflicts with components existing in both packages support numbered ones and androidx. That's why I attached the similarity table.
@code4rox Just because it doesn't make sense to you. You can't downvote an answer. OP's error explicitly says "[com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] "
MD Naseem Ashraf u can clear see in gradle the his project not completely converted to AndroidX so just enough android.enableJetifier=true android.useAndroidX=true
@code4rox OP Just said setting jetifier and androidx to true did not help.
4

you have to move on the Androidx because your project is using some feature from there.so you need to migrate to AndroidX follow these snippetsclick on the Refractor and then click on migrate to AndroidX

look at this second snippetmake sure you have check on back project as zip file

1 Comment

Don't follow this advice. I migrated to androidX but still same error comes out.
1

One suggestion to find out the exact reason is to open the manifest file and in bottom you will see a Merge Manifest option where you will see exact reason for failure.

See below image

enter image description here

3 Comments

This should be a comment and not an answer.
@MDNaseemAshraf as you can see I have added image too, other wise i would have added it in comment only
@Androidenthu. You can link the screen shot in your comment via imgur. I would suggest you to do that.
1

Just add a line into gradle.properties

android.enableJetifier=true android.useAndroidX=true 

Comments

0

Project-wide Gradle settings. IDE (e.g. Android Studio) users: Gradle settings configured through the IDE will override any settings specified in this file. For more details on how to configure your build environment visit http://www.gradle.org/docs/current/userguide/build_environment.html

Specifies the JVM arguments used for the daemon process. The setting is particularly useful for tweaking memory settings

org.gradle.jvmargs=-Xmx1536m android.enableJetifier=true android.useAndroidX=true 

When configured, Gradle will run in incubating parallel mode. This option should only be used with decoupled projects. More details, visit http://www.gradle.org/docs/current/userguide/multi_project_builds.html

sec:decoupled_projectsvorg.gradle.parallel=true 

Comments

0

I also faced this problem because I was using some external library in my project and one of them was not converted into AndroidX.

Comments

0

add below code to android/build.gradle under buildscript ext

googlePlayServicesVersion = "16.0.0" googlePlayServicesVisionVersion = "17.0.2" 

and below code to gradle.properties

android.enableJetifier=true android.useAndroidX=true 

Comments

0

I let Android Studio convert my Relative layout views to Constraint layout. So Android Studio added one of the com.andriod.support... while I added the androidx... dependency when I removed the second one the error was gone.

dependencies { implementation "androidx.constraintlayout:constraintlayout:2.1.0" implementation 'com.android.support.constraint:constraint-layout:2.0.4' } 

This was my error:

Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.3.2] AndroidManifest.xml:24:18-86 is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:3-26:17 to override. 

Comments

0
 implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:design:28.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:one.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 

Comments

0

In manifest add tools:replace="android:theme" to your application

Comments

0

I have resolve problem by removing

 implementation 'com.android.support.constraint:constraint-layout:2.0.4' 

from app build.gradle and using

implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.google.android.material:material:1.1.0-alpha04' 

instead of it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.