Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android X: tools:replace specified at line: for attribute, but no new value specified

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">
       ...
like image 995
Malwinder Singh Avatar asked Nov 12 '18 19:11

Malwinder Singh


6 Answers

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

like image 136
Akshay Avatar answered Nov 16 '22 01:11

Akshay


You can try adding:

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

To the tag <application > in your manifest.

like image 43
Gabriel Aguirre Avatar answered Nov 16 '22 03:11

Gabriel Aguirre


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

like image 13
shailesh Avatar answered Nov 16 '22 02:11

shailesh


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.

like image 6
codepeaker Avatar answered Nov 16 '22 03:11

codepeaker


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.

like image 5
komaki Avatar answered Nov 16 '22 02:11

komaki


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.

like image 5
Nikhil Lotke Avatar answered Nov 16 '22 02:11

Nikhil Lotke