Android Material and appcompat Manifest merger failed
Asked Answered
G

35

241

I have next grade

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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'
    implementation 'com.google.android.material:material:1.0.0-rc01'
}

But when I want to build app I get next log:

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

Okey! Go to manifest and do it:

<?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="ru.chopcode.myapplication">

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

</manifest>

Then I get this error in my Logcat:

Manifest merger failed with multiple errors, see logs that I have Linked with it
Gelsenkirchen answered 10/8, 2018 at 19:58 Comment(5)
Try removing these lines: implementation 'com.android.support:appcompat-v7:28.0.0-rc01' and implementation 'com.android.support.constraint:constraint-layout:1.1.2'Reredos
I think material packages are all bundled into android-design, check it out...Athelstan
I need this: material.io/design/components/app-bars-bottom.html. This is into android-design?Glynas
You can check this one too : https://mcmap.net/q/119238/-manifest-merger-fails-for-appcomponentfactory-duplicatePeddling
New android studio have feature to migrate your application to androidX smoothly. follow below link. github.com/material-components/material-components-android/…Corporate
B
15

Just change "rc01" in first and last line inside dependencies to "alpha1" This is working for me

Bickering answered 10/8, 2018 at 20:27 Comment(3)
More than one file was found with OS independent path 'META-INF/androidx.core_core.versionReflective
I dont have "rc01" written in implementation 'com.android.support:appcompat-v7:28.0.0'. Still getting the issue. Please suggest some solution.Mytilene
This answer should have been a comment to the question.Privett
D
485

I had similar problem. Added two lines in gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

These two lines automatically resolved my dependency conflicts between google's files and third party dependencies. Here's the link to follow: https://developer.android.com/topic/libraries/support-library/androidx-overview#new-project

Dionysian answered 29/9, 2018 at 3:23 Comment(7)
after added this following error happens ``` * What went wrong: Execution failed for task ':react-native-camera:compileGeneralDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. ```Kondon
@PrinceHamza check this we found a solution for this github.com/facebook/react-native/issues/…Kondon
This should be the accepted answer. This solved the problem.Augite
"But I don't see a 'gradles.properties file' "!. Yes, so in the app's root folder in studio project , create that file (no extension) and adds those lines.Godroon
After do this I have got Could not set unknown property 'useAndroidX' for object of type com.android.build.gradle.AppExtension. errorLest
it worked for me but i have to change all tags in xml files that use support library like constraintLayout and toolbar and in the java classes either! it take a long time.Farrison
android.enableJetifier=true worked for me ... the androidX reference was already there. +1Mure
R
148

I faced same error when i try to add Kotlin-KTX library to my project.

I try to AndroidX migration, and problem fixed!

Refactor/Migrate to AndroidX

Reprobate answered 10/11, 2018 at 20:3 Comment(2)
This works, but some of the import statements that it generates use outdated package names. I had to fix a bunch of them, just by using whichever androidx.* package name the IDE suggested as a fix.Pyriform
I ran into this issue because I was pulling the latest release of "support-v4" library in my build.gradle file...not a good practice. Had I been referencing a specific version of the library within my gradle file, I would have never run into this issue in the first place. Also, after I researched a little more, I could see that Google was recommending switching to the AndroidX library; so, I decided to bite the bullet. Fortunately, all problems resolved after the upgrade...disaster averted and LESSON LEARNED about the gradle references.Caia
A
110

Reason of Fail

You are using material library which is part of AndroidX. If you are not aware of AndroidX, please go through this answer.

One app should use either AndroidX or old Android Support libraries. That's why you faced this issue.

For example -

In your gradle, you are using

  • com.android.support:appcompat-v7 (Part of old --Android Support Library--)
  • com.google.android.material:material (Part of AndroidX) (AndroidX build artifact of com.android.support:design)

Solution

So the solution is to use either AndroidX or old Support Library. I recommend to use AndroidX, because Android will not update support libraries after version 28.0.0. See release notes of Support Library.

Just migrate to AndroidX.Here is my detailed answer to migrate to AndroidX. I am putting here the needful steps from that answer.

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

What is Jetifier?

Agadir answered 5/2, 2019 at 11:46 Comment(2)
Still had an error afterwards, but this answer helped: https://mcmap.net/q/98065/-default-interface-methods-are-only-supported-starting-with-android-7-0-nougatIrresponsible
Please remember to Click "Do refactor" in the bottom left after clicking "Migrate to AndroidX"Constraint
T
97

In my case, this is working perfectly.. I have added below two line codes inside manifest file

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"

Credit goes to this answer.

Manifest file Example

Trautman answered 8/11, 2018 at 5:38 Comment(8)
I do not know if I will have a problem in my app later on, but it worked!Reflective
Yes I had a problem: More than one file was found with OS independent path 'META-INF/androidx.core_core.versionReflective
then i get an error stating tools is not bound to the application tag.Varion
Can you post full logcat?Trautman
I had to tools to the namespace: github.com/magus/react-native-facebook-login/issues/…Berneta
can you elaborate? @JohannesTrautman
I am getting the error "The prefix "tools" for attribute "tools:replace" associated with an element type "application" is not bound."Woll
This solution works also on Xamarin. I had to add the tools namespace xmlns:tools="https://schemas.android.com/tools" to the manifest tag and I used androidx as appComponentFactory in place of whateverString Cockeye
T
30

Simple Solutions - migrate into AndroidX

in the gradle.properties, just add below two scripts

android.useAndroidX=true
android.enableJetifier=true

What was the reason ↓

All packages in AndroidX live in a consistent namespace starting with the string androidx. The Support Library packages have been mapped into the corresponding androidx.* packages. For a full mapping of all the old classes and build artifacts to the new ones, see the Package Refactoring page.

Please see the Package Refactoring page

Tuner answered 12/6, 2019 at 11:57 Comment(3)
There is no such file gradle.properties in my project. (It is originally created in eclipse years ago and later moved to android studio)Besmirch
Oh... I didn't face such a situation, I found below thread that might help you https://mcmap.net/q/119240/-android-studio-where-is-gradle-properties-file Try and do comment pleaseTuner
Just create that file near main build.gradle if it does not exists and sync the project.Liebknecht
B
15

Just change "rc01" in first and last line inside dependencies to "alpha1" This is working for me

Bickering answered 10/8, 2018 at 20:27 Comment(3)
More than one file was found with OS independent path 'META-INF/androidx.core_core.versionReflective
I dont have "rc01" written in implementation 'com.android.support:appcompat-v7:28.0.0'. Still getting the issue. Please suggest some solution.Mytilene
This answer should have been a comment to the question.Privett
E
14

Just remove the android.support dependancy

    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

Quoting From Material Guidelines

If you don’t want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0-alpha3 dependency.

Note: You should not use the com.android.support and com.google.android.dependencies in your app at the same time.

Just removing this dependency works fine

    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

Here is complete dependencies example

    dependencies {
       implementation fileTree(dir: 'libs', include: ['*.jar'])
       implementation 'com.google.android.material:material:1.0.0-beta01'
       implementation 'com.android.support.constraint:constraint-layout:1.1.2'
       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'
   }
Epanaphora answered 19/8, 2018 at 7:30 Comment(3)
This is the most accurate answer.Magma
@FranMarzoa It is not. What happens when the compat library is imported from another dependency?Rothenberg
@Rothenberg that you'd have to post a different question here, I guess... ;)Magma
D
13

As of Android P, the support libraries have been moved to AndroidX

Please do a refactor for your libs from this page.

https://developer.android.com/topic/libraries/support-library/refactor

Dna answered 20/8, 2018 at 7:26 Comment(0)
L
13
  1. Please go to Refactor->Migrate->Migrate to Android X.

  2. Please add this to your gradle.properties file:

    android.enableJetifier=true
    android.useAndroidX=true
    

And perform Sync.

Lordsandladies answered 29/7, 2019 at 6:57 Comment(5)
Can you please explain, what is your situation now?Lordsandladies
The project i inherited is half a decade old. I tried to implement new Fabric/Firebase analytics that google is pushing. And that new library is using androidx compatibility libraries, and my project uses AppCompat. Now, i had to deal with tons of dependency updates and stuff. I came to a halt, and then tried various things, including these commands, and i need them because of new Firebase stuff. After i turned this on i got tons of compiler errors. Fixed that but now i have errors coming from ui xml files.. So i will have to abandon everything, and try with older versions.Pokelogan
After one more hour of manually fixing class namespaces to androidx, it seems to work now. Trouble is, compiler could not detect in xml that for example: "android.support.v7.widget.AppCompatSpinner" needs to be "androidx.appcompat.widget.AppCompatSpinner". This document came in handy: developer.android.com/jetpack/androidx/migratePokelogan
Hope it's working now, let me know if anything goes wrong.We shall work on it!Lordsandladies
be very careful with this. it will effect the entire file tree. i was working in a real code area and almost refactored hundreds of files. isolate the projects in their own path before doing this. also beware if your using fragments it will change the fragment imports to: import androidx.fragment.app.Fragment; scary very scaryTrattoria
B
13

See This Image and Add This line in your android AndroidManifest.xml

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"

enter image description here

Bootlace answered 21/8, 2019 at 6:44 Comment(3)
whatever string means ?Shifra
@KishoreKumar you can add any string name like appName also.Bootlace
to be precise, whateverString should be a full class name which extends AppComponentFactory. for example, a custom defined class com.xxx.MyFactory extends AppComponentFactorySkinflint
H
12

Add these lines inside in AndroidManifest.xml file.

tools:replace="android:appComponentFactory"

android:appComponentFactory="whateverString"
Halette answered 21/6, 2019 at 15:45 Comment(5)
tools is becoming red when adding it. is there other things needed to add?Fruma
No nothing more to add. One reason maybe is ur gradle version is mismatched. Can u show ur AndroidManifest.xml file code?Halette
I tried migrating to androidx and I keep having Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details.Fruma
Here is my android manifest <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher" android:usesCleartextTraffic="true" android:supportsRtl="true" android:theme="@style/AppTheme" tools:replace="android:appComponentFactory" android:appComponentFactory="@string/texthere" >Fruma
Great Solution , Saved my time.Ibbie
P
10

just add these two lines of code to your Manifest file

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Publicly answered 19/6, 2019 at 8:57 Comment(0)
A
9

Migrate to androidX if it an existing project. If it is new project add these two flags to Gradle.propeties

android.enableJetifier=true  
android.useAndroidX=true

for more detail steps https://developer.android.com/jetpack/androidx or check this What is AndroidX?

Atop answered 1/8, 2019 at 22:29 Comment(0)
D
8

Follow these steps:

  • Goto Refactor and Click Migrate to AndroidX
  • Click Do Refactor
Dejecta answered 12/1, 2019 at 14:9 Comment(1)
This will not do the entire refactor :(Ari
C
7

Only If you don't want to use androidx

So in my case, I am using a library that was using androidx but I am not using androidx so when I downgraded that library version the problem was resolved.

In my Case:

implementation 'com.github.turing-tech:MaterialScrollBar:13.+'

the above-mentioned library makes problem 13.+ will automatically get a new version of the library which using androidx. So I downgraded library version to:

implementation 'com.github.turing-tech:MaterialScrollBar:13.2.5'

And the problem was resolved.

Cherin answered 30/12, 2018 at 12:6 Comment(0)
P
6

Finally found a quick and easy solution by adding two lines in the android/build.gradle file.

googlePlayServicesVersion = "16.+"

firebaseVersion = "17.6.0"

Please follow this 100% correct.

Publicly answered 10/8, 2018 at 19:58 Comment(5)
Where do even add this?Varion
Add this in android/build.gradle filePublicly
@ManojAlwis in which section of build.gradle file we need to put this?Religiose
@KevalLangalia, just add these two lines to android -> build.gradle file . eg: buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 19 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "28.0.0" googlePlayServicesVersion = "16.+" firebaseVersion = "17.3.4" }Publicly
really helpful... Thank youOvernice
P
6

This issue mainly happened for old dependencies.

There have 2 solution:

First one:

Update all old dependencies and ClassPaths from Project level gradle files.

classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'

Second one:

Your project Migrate to AndroidX

From Android Studio Menu -> Refanctor -> Migrate to AndroidX

Thanks, let me know if anyone help from this answer.

Pitchman answered 23/2, 2019 at 12:44 Comment(0)
B
6

Its all about the library versions compatibility

I was facing this strange bug couple of 2 hours. I resolved this error by doing these steps

hange your build.gradle dependencies into

  implementation 'com.google.android.gms:play-services-maps:17.0.0'

to

  implementation 'com.google.android.gms:play-services-maps:15.0.0'
Borehole answered 27/7, 2019 at 16:2 Comment(1)
Honestly i did the same and it worked, so i guess its all about the library versions compatibility after merging proccessPhelps
B
5

All I did was go to the "Refactor" option on the top menu.

Then select "Migrate to AndroidX"

Accept to save the project as a zip file.

Please update Android Studio as well as Gradle to ensure no problems are encountered.

Berkeleian answered 7/7, 2019 at 18:31 Comment(0)
N
4

Create new project and compare your build.gradle files and replaced all

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'

and other dependencies with the same as were in a new project someting like that

implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'

implementation 'androidx.constraintlayout:constraintlayout:1.1.2'

implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'

androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

implementation 'androidx.core:core-ktx:1.0.0-alpha3'

And then fixed imports to use androidx in kotlin files.

Nod answered 10/8, 2018 at 20:8 Comment(1)
Because o some reason, I dont want to use androidx.Canoness
S
4

1.Added these codes to at the end of your app/build.gradle:

configurations.all {
   resolutionStrategy.force 'com.android.support:support-v4:28.0.0' 
   // the above lib may be old dependencies version       
    }

2.Modified sdk and tools version to 28:

compileSdkVersion 28
buildToolsVersion '28.0.3'
targetSdkVersion  28

3.In your AndroidManifest.xml file, you should add two line:

<application
    android:name=".YourApplication"
    android:appComponentFactory="AnyStrings"
    tools:replace="android:appComponentFactory"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

Or Simply

  • Go to Refactor (Studio -> Menu -> Refactor)
  • Click the Migrate to AndroidX. it's working
  • it's working.
Sculpturesque answered 22/5, 2019 at 1:41 Comment(0)
Y
4

If you do not intend to migrate to AndroidX follow the below steps

  1. In terminal type gradlew app:dependencies
  2. After dependencies are shown in the window press Ctrl+f and type androidX
  3. You will find all the dependencies which are using androidx lib internally you may have to downgrade that or use alternative for that to ensure it is no longer using androidX libs internally.
Yoicks answered 5/7, 2019 at 12:48 Comment(0)
G
2

First of all be sure to add this line in manifest tag

xmlns:tools="https://schemas.android.com/tools"

Then add tools replace your suggested one in Android studio

Gittern answered 4/12, 2018 at 5:25 Comment(0)
S
2
  • Go to Refactor (Image )
  • Click the Migrate to AndroidX. it's working
  • it's working.
Sestos answered 13/6, 2019 at 20:49 Comment(1)
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.Ebonize
F
2

Try this

tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"

Rebuild your project.

Feudist answered 10/6, 2020 at 11:32 Comment(0)
S
1

I had this same problem for three days.

It is like android wants us to either use Kotlin Or AndroidX, they are doing away with Android.

But this is how I solved it.

  • I migrated my project to AndroidX. This does not bring in any errors related to this issue in question, It updates files respectively. No method, class or variable name needs to be changed in your application.

NB: You must be using the latest Libraries (build.grudle file) in the latest stable version of android studio 3.4.1

Stettin answered 3/7, 2019 at 9:52 Comment(0)
A
1

I don't know this is the proper answer or not but it worked for me

Increase Gridle Wrapper Property

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

and Build Gridle to

    classpath 'com.android.tools.build:gradle:3.4.2'

its showing error because of the version.

Ambrosia answered 8/11, 2019 at 6:49 Comment(1)
I think the string should be androidx.core.app.AppComponentFactory, arbitrary strings will cause random errors some times.,Mordy
C
0

I had the same error when working with Groupie. implementation 'com.xwray:groupie:2.3.0'

I solved it by changing version to implementation 'com.xwray:groupie:2.1.0'

Cunnilingus answered 28/1, 2019 at 15:41 Comment(0)
L
0

In may case I didn't want to pass to androidX. And I have to check my last changes. I figure out that the new component was --> lottie 2.8.0

So I downgrade it to: implementation 'com.airbnb.android:lottie:2.7.0'

Lachus answered 6/3, 2019 at 15:51 Comment(0)
E
0

Change proguardFile in build.gradle (Module: app) to the following

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

instead of

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

This worked for me

Excruciating answered 25/3, 2019 at 13:44 Comment(0)
P
0

For solving this issue i would recommend to define explicitly the version for the ext variables at the android/build.gradle at your root project

ext {
    googlePlayServicesVersion = "16.1.0" // default: "+"
    firebaseVersion = "15.0.2" // default: "+"

    // Other settings
    compileSdkVersion = <Your compile SDK version> // default: 23
    buildToolsVersion = "<Your build tools version>" // default: "23.0.1"
    targetSdkVersion = <Your target SDK version> // default: 23
    supportLibVersion = "<Your support lib version>" // default: 23.1.1
}

reference https://github.com/zo0r/react-native-push-notification/issues/1109#issuecomment-506414941

Presignify answered 25/7, 2019 at 12:8 Comment(0)
G
0

I'm also facing the same issue, for your android studio, you just change the android Gradle plugin version 3.3.2 and Gradle version is 5.1.1

Gustavogustavus answered 16/9, 2019 at 6:53 Comment(0)
M
0

in my case i am add in manifest file `

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"

application tag of course, It will work

Mintun answered 17/2, 2020 at 12:13 Comment(0)
S
0

if you are using capacitor, upgrade to capacitor/core 2.0.1 or up in your package.json

Surpass answered 11/4, 2020 at 9:51 Comment(0)
D
-3

change your build.gradle dependencies into

 implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'

or

 implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
Dejecta answered 12/1, 2019 at 13:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.