85

I have tried many solutions on this website but still, the problem is not solved. The issue is due to Android X library. When I added Android X, this issue was resolved but it opened up new issue. How to fix this issue?

Earlier this error was coming:

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:19:5-142:19 to override.

After I added tools:replace="android:appComponentFactory", this error is came:

 java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
at com.android.builder.core.AndroidBuilder.mergeManifestsForApplication(AndroidBuilder.java:540)    
at com.android.build.gradle.tasks.MergeManifests.doFullTaskAction(MergeManifests.java:173)

Merging Error (in Android Manifest):

Error: tools:replace specified at line:2 for attribute android:appComponentFactory, but no new value specified app main manifest (this file), line 1

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    package="com.example"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:replace="allowBackup, android:appComponentFactory"
    android:allowBackup="false">

    ...

    <application
        android:name="com.example"
        android:icon="@mipmap/icon"
        android:debuggable="true"
        android:hardwareAccelerated="false"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:allowBackup="false"
        tools:ignore="GoogleAppIndexingWarning,HardcodedDebugMode">
       ...
Malwinder Singh
  • 6,644
  • 14
  • 65
  • 103

13 Answers13

114

I think you are migrating to AndroidX libs.

Add below lines to gradle.properties file

android.useAndroidX=true
android.enableJetifier=true

Remove tools:replace="android:appComponentFactory" from manifest.

Replace import from android.support.v7.app.AppCompatActivity to androidx.appcompat.app.AppCompatActivity in activities. Use replace in project to expedite the process of refactoring.

Migrating to AndroidX

Akshay
  • 1,702
  • 1
  • 9
  • 16
  • 6
    Where should I replace android.support.v7.app.AppCompatActivity ? – Lucky_girl Jun 18 '19 at 09:24
  • @Lucky_girl You must be using `android.support.v7.app.AppCompatActivity`. This means you must have created children activities of this activity. Replace them with `androidx.appcompat.app.AppCompatActivity ` – Malwinder Singh Jun 26 '19 at 12:45
  • I did everything same but getting this error : `Manifest merger failed : Attribute application@appComponentFactory value=(whateverString) from AndroidManifest.xml:26:9-53 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 element at AndroidManifest.xml:23:5-149:19 to override. ` – Ali Akram Jun 27 '19 at 09:29
  • @AliAkram that happens when your app, that isn't configured for AndroidX, uses a library that actually uses AndroidX. What you should do is look at the library release history and see if there's a release prior to that libraries' switch to AndroidX. Finally write yourself a work item to convert your app to AndroidX - it can take quite a while depending on the size of the project. – Someone Somewhere Jul 16 '19 at 23:37
42

You can try adding:

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

To the tag <application > in your manifest.

Gabriel Aguirre
  • 589
  • 4
  • 9
13

I got same error in my project, I have resolved it You can try it

Android Studio > Refactor > Migrate to AndroidX

enter image description here

shailesh
  • 449
  • 5
  • 11
8

I added below lines inside <application> tag

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

below lines inside gradle.properties file

android.useAndroidX=true android.enableJetifier=true

Rebuild your project.

Nikhil Lotke
  • 605
  • 7
  • 15
6

In my case, I had updated Firebase and play services dependency, result in this issue.

Reverted back the dependency updates and the error vanished

Seems that the latest Firebase and Play Service dependencies are compatible with androidx.

codepeaker
  • 420
  • 8
  • 15
5

It often happened because you used Androidx libraries and support libraries at the same time. Some 3rd-party libraries may contain support libraries and other 3rd-party libraries may contain Androidx libraries, this can also lead this problem. If you have gradle environment in you PC, try "gradlew :app:dependencies" command in the terminal of Android Studio, this command will list all libraries including 3rd-party libraries of your project, and see which library or framework used Androidx libraries and which not. Then try to upgrade old libraries used support libraries, and this problem should disappear.

komaki
  • 49
  • 1
  • 2
4

migrate to android x

add below lines inside tag

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

then also add below lines inside gradle.properties file

  android.useAndroidX=true
  android.enableJetifier=true

Rebuild your project.

4

In build.gradle

//noinspection GradleCompatible
implementation 'com.android.support:design:28.0.0'

In gridle.properties add following line

android.enableJetifier=true

In AndroidMenifest.xml in <menifest ...

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

and in <application ... add following attributes

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

you need just add this code in gradle.properties file

android.useAndroidX=true
android.enableJetifier=true
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
2

In my case, i was facing problem because of the firebase version i was using. Downgrading the firebase version helped me.

implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' implementation 'com.google.firebase:firebase-core:16.0.6'

Rishabh Gupta
  • 113
  • 1
  • 9
1

in my case I have problem with

tools:replace="android:usesCleartextTraffic"

I have already use AndroidX, I have already have these properties in gradle.properties

android.useAndroidX=true
android.enableJetifier=true

the problem is I forget to set the value to be true (or it can be false, depends on your case)

<application
        android:label="myApp"
        tools:replace="android:usesCleartextTraffic"
        android:usesCleartextTraffic="true"> // I forget this line
Alexa289
  • 8,089
  • 10
  • 74
  • 178
0

Just configure your manifest application tag this way

<application
        android:fullBackupContent="true"
        android:usesCleartextTraffic="true"
        tools:targetApi="m"
        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/Theme.Media">
ilidiocn
  • 323
  • 2
  • 5
0

source of these errors for me was adding v4 design support library for TabLayout.

thread Manifest Merger fails for appComponentFactory helped,

after setting:

android.useAndroidX=true
android.enableJetifier=false

I faced issues with tools name space. Problem was, in manifest I had tools:replace="android:appComponentFactory" but adding android:appComponentFactory="androidx" resolved at-least manifest merge errors.

However when tried to link setup TabLayout with ViewPager using, it seems pager needs to be android.support.v4.view.ViewPager but i got androidx.viewpager.widget.ViewPager

        //attach pager adapter
        SectionPagerAdapter pagerAdapter = new SectionPagerAdapter(getSupportFragmentManager());
        ViewPager pager = (ViewPager)findViewById(R.id.pager);
        pager.setAdapter(pagerAdapter);

        //attach viewpager with tablayout
        TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
        tabs.setupWithViewPager(pager);