Manifest Merger fails for appComponentFactory [duplicate]
Asked Answered
S

8

31

Using Google's so called Material Design 2.0 requires you to add

implementation 'com.google.android.material:material:1.0.0-rc01'

in the app Gradle which also includes

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

which shows conflicts

Here's what the log says

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0-rc02] AndroidManifest.xml:22:18-91   

is also present at [androidx.core:core:1.0.0-rc01] 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.

Even after adding that to the Manifest it shows Manifest Merger failed with multiple error

Saundrasaunter answered 2/9, 2018 at 8:30 Comment(0)
K
30

This error is common nowadays:

When we get this types of error: When library is updated and providing use of AndroidX but we are using old one.

You can follow the steps to solve this:

  • Migrate your project to AndroidX:

With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

Note: To migrate an existing project that does not use any third-party libraries with dependencies that need converting, you can set the android.useAndroidX flag to true and the android.enableJetifier flag to false.

THIS STEP WILL DO EVERYTHING AUTOMATICALLY THAT ALL ANSWER SAYS TO DO MANUALLY

  • You can check Overview of AndroidX here.
  • More details for migration

Even If you get any other error like run-time build failed, then:

  • Invalidate cache and restart

OR

  • Clean your project

Hope it will helps to all. Thank you.

Kerouac answered 22/2, 2019 at 10:58 Comment(4)
I prefer this one, because it will auto backup for our old project.Nellynelms
Please remember to Click "Do refactor" in the bottom left after clicking "Migrate to AndroidX"Wilburnwilburt
this solution works like a charmKoller
Just to help further: set android.useAndroidX=true in gradle.properties, and same for enableJetifierCranium
S
18

To fix this you have to add the tools namespace and apply the suggested attributes to the application element recommended by the IDE.

<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">

Source

Suksukarno answered 3/12, 2018 at 12:46 Comment(1)
This is giving issue: tools:replace specified at line:23 for attribute android:appComponentFactory, but no new value specifiedUella
R
10

Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:5:5-19:19 to override.

If you added the tools:replace="android:appComponentFactory" and still got trouble by fixing it, create a new project, copy-paste the codes and the same dependencies in there. After that, it should be fixed i hope.


If it didn't solve the issue, try adding these two:

tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx"

In AndroidManifest.xml > <application tag of course.

Remount answered 2/9, 2018 at 8:47 Comment(3)
java.lang.ClassNotFoundException: Didn't find class "site.foxtransport.foxtaxi.whateverString"Ogpu
Can you try with android:appComponentFactory="androidx"?Rundell
Yes, I have tried, thank you. It looks like in such a case anything lower than API 28 is incompatibleOgpu
F
7

Replace all android dependencies with androidx ones in build.gradle file.

For example:

implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'androidx.annotation:annotation:1.0.0'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
Fillip answered 27/9, 2018 at 11:51 Comment(1)
This lead me to the solution for my setup! Thank you!Subrogation
T
2

Replace in dependencies from:

implementation 'com.google.android.material:material:1.0.0-rc01'

to:

implementation 'com.android.support:design:28.0.0'
Tokharian answered 10/11, 2018 at 22:19 Comment(0)
D
-1

try : replace rc01 >> alpha1 . It's working for me !

Dupe answered 8/10, 2018 at 7:11 Comment(1)
I think this can be a comment and not an answerHabited
Z
-1

I also had this issue and I migrated to AndroidX, following the official documentation. Only via Refactor -> Migrate to AndroidX.

Migration to AndroidX Official Docs

Hope this helps.

Zeitler answered 10/5, 2019 at 18:19 Comment(0)
Z
-3

Deselecting instant run worked for me. Not sure if it helps for everyone.

Zeeland answered 6/3, 2019 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.