Manifest merger failed when using leakcanary 2.0 alpha 2 - android

I am using leakcanary 1.6.3 in my project to find memory-leaks without any problem using:
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
Now I want to update it to leakcanary 2.0 alpha 2 using:
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-alpha-2
But when I try to build project, it gives me manifest merger failed.
ERROR: 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.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:10:5-50:19 to override.
How do I fix this error?
Update: I am using android.support libraries in my project.

After some research in leakcanary 2.0 alpha 2 code, I found that the new version of library uses androidx libraries but I am using android.support libraries in my project. If I refactor my project to use androidx then no error occur.
It seems that:
A project using androidx can use a library that uses android.support
But a project using android.support can not use a library that uses androidx
This SO answer explain androidx and how to migrate your project to androidx.

Related

ERROR: Manifest merger failed : Attribute application#appComponentFactory in android [duplicate]

This question already has answers here:
Manifest merger failed : Attribute application#appComponentFactory - Androidx
(14 answers)
Closed 2 years ago.
I'm not able to use android.support.v7.app.AppCompatActivity. It shows error on import android.support.v7.app.AppCompatActivity; as follows: Cannot resolve symbol 'v7'. I have even added implementation 'com.android.support:appcompat-v7:28.0.0' in the build.gradle.
After setting android.useAndroidX=true and android.enableJetifier to false in the gradle.properties, the above mentioned error resolves but instead, I'm getting an error as follows: ERROR: 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.5.0-alpha02] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:5:5-20:19 to override. Even after adding tools:replace="android:appComponentFactory to AndroidManifest.xml, I'm getting the same error.
I'm using compileSdkVersion 28 and targetSdkVersion 28.
This is primarily happening because you are using Androidx with the v28 support library , you can remove the v28 library if you are using the androidx library , if you are using the v28 support library do otherwise.
androidx.core:core:1.5.0-alpha02
Well the error says that because androidx core and v28 are conflicting. Use either one. And androidx core also has the same methods as the v7.AppCompatActivity has , so why don't you migrate it to androidx using
import androidx.appcompat.app.AppCompatActivity

Manifest merger failed - Don't want to migrate to androidx

I don't want to migrate to androidx. what can I do???
ERROR: 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.1.0] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:25:5-120:19 to override.
Not migrating to Androidx will be delimiting to you in the future. If you are sure that your application will not use new APIs or Libraries in the future, then feel free to stick with the Android nomenclature. But if you are not certain, then going through the painful process is worth it.
There are documentations that help you to perform this HUGE migration, basically by using incremental approach. Feel free to refer to this document and follow it religiously, by performing small increements.
Blogs
Androidx official documentation
Cross stitching android and Androidx
Migrating to Androidx Tips
Video guides
Androidx Video Guide

Dagger and Butterknife

I am using dagger2 in my app. But when I started project my activities was extended support AppcompatActivity.Now while build I am getting warning via butterknife.
API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'.
To fix this I must upgrade butterknife version from 9.0.0-rc1 to 10.2.0 when I change version butterknife to 10.2.0 I am getting error to build.Because I am not using androidx. error like this:
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 element
at AndroidManifest.xml:9:5-70:19 to override.
So I don't know how to fix this issue.If somebody had such kind of error and warning please help me if you fixed it
Migrate your project to AndroidX, butterknife 10.2.0 is on androidX.
It literally says what you need to do. Add tools:replace="android:appComponentFactory" like this: <application tools:replace="android:appComponentFactory"

How to find which library use AndroidX - [Resolved]

I'm using react native and my Android project isn't compiling anymore because of this error:
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:28:5-109:19 to override.
I've tried to add that tag but I'm getting always errors!!
I've tried to remove all packages to find which had androidX support or how to fix this bug, but I've been stuck for days!
Thanks!
UPDATE
I've opened all gradle files of the libraries and one at the time I've checked the dependencies, excluding or changing the version of some.
A terrible work but now I'm able to compile...
Thanks to all!
This is probably related to a Google update on the google place services. You can find which library is using AndroidX with this command:
gradlew app:dependencies
App is the name of your module/project but that is usually the default one.
If you can't solve this this way, post your project and app build.gradle
Make sure that you import the right version for AndroidX from here: https://developer.android.com/jetpack/androidx/migrate
I got stuck one day also just because integrate wrong version. So check it just to be sure.

AndroidManifest error related to AndroidX when trying to build React Native 0.59 app

I'm trying to build a React Native Android application following an upgrade to RN 0.59.9, but I'm getting an error related to AndroidX.
I've tried many things including removing most native packages, changing AndroidManifest.xml and various other solutions mentioned on the internet but nothing seems to work.
My error is this:
> Task :app:processReleaseManifest FAILED
....\android\app\src\main\AndroidManifest.xml:22:18-91 Error:
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:35:2-108:16 to override.
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
FAILURE: Build failed with an exception.
As I understand it means one of the package uses AndroidX but not the main app, however as far as I can tell nothing in my app uses AndroidX, and I made sure to upgrade to RN 0.59, not 0.60. I've even tried to grep "androidx" and remove all the packages that might mention it.
I've also tried to add "android.useAndroidX=true / android.enableJetifier=true" to gradle.properties just to see what happens but as expected many modules don't build since they have not been upgraded to AndroidX.
Any idea how to fix this bug?
This is most likely due to Android releasing all AndroidX libraries, and '+'-style gradle dependencies leaking in.
You can either ./gradlew :app:dependencies|grep androidx to find the problem libraries and then use gradle resolutionStrategies or android/build.gradle ext{} versioning to pin the Google library dependency, or you can convert your react-native project to androidx and use the jetifier tool via npm i jetifier && npx jetify so that non-androidx react-native libraries work.
Either should result in a working build as the react-native ecosystem transitions to AndroidX

Categories

Resources