Manifest merger failed with mutliple errors - android

Is there any idea how to resolve this issue?
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.

Find your issue in mergedmanifest on the android manifest
If the issue is on appComponentFactory then you have to migrate to androidx
Reason : dependency update

Migrate your dependency to AndroiX,
Auto:
Refactor => Migrate to AndroidX
Manual:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

The problem is because android has released a new version and they are depreciating the 28.0.0. The new version is called androidx 1.0.1(beta).This happens because you must have upgraded your android studio or the gradle version of studio.So go to
1)Click Refactor from menu options in Android studio.
2)Click Migrate to Android X from Refactor.
3)It will ask us to create a backup zip file and proceed with backup process. Click migrate.
4) Now this will show the refactor window with the list of all the files using android support libraries. Just click Do Refactor and relax.
5) Now you can see all the support libraries used in the project have been imported to AndroidX dependencies.

Related

gradle not syncing when adding firebase to android studio

So I'm trying to add the Firebase SDK to my Android Studio app as per the instructions from the Firebase website (see picture).
Adding the line classpath 'com.google.gms:google-services:4.3.2' to the project level gradle works fine. I can sync the gradle files.
However, adding the line apply plugin: 'com.google.gms.google-services' to the app level gradle file breaks my app.
I get the following error:
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 element at AndroidManifest.xml:5:5-21:19 to override.
So i go to do the suggestion. I add tools:replace="android:appComponentFactory" to >application< element in AndroidManifest.xml file. This then gives me a Namespace "tools" not bound error. I press Alt+Enter to fix which adds xmlns:tools="http://schemas.android.com/tools" to the top of my file.
Try sync again. Now i get a similar error: ERROR: Manifest merger failed with multiple errors, see logs. And this is where I'm lost. I'm not sure what to search in Google. a search for this specific error brings up a lot of answers that aren't related to my problem. This territory is completely new to me.
P.S. On top of all that, the line implementation 'com.android.support:appcompat-v7:28.0.0'inside my build.grade(app level) file is underlined red after adding the previously mentioned 3 lines.
I noticed there's other questions related to this but none seem to have solid answers. So I'm taking the risk that this might be a repost.
EDIT::
Here are my gradle depencies.
Project Gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.gms:google-services:4.3.2'
}
App Gradle
dependencies {
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
EDIT 2::
Ok after migrating to androidx, I updated all my import statements to use androidx. It still kept saying merger failed with multiple errors. I had to delete the line tools:replace="android:appComponentFactory" that it had previously suggested to add. Finally I was able to sync and run my app! Except now the app just starts and stops immediately. I suppose that's progress. Any ideas on this?
EDIT 3::
I finally got it to work. The last issue was a RunTimeError "Error inflating class androidx.constraintlayout.ConstraintLayout". This is caused because all my xml files had the line androidx.constraintlayout.ConstraintLayout. replaced this with the line androidx.constraintlayout.widget.ConstraintLayoutand everything is gravy now. Gradle syncs, app loads, doesn't crash and everything works as it's supposed to
Any help would be greatly appreciated.
Thx in advance,
Vlad
The problem is your app is using android.support libraries while the Firebase sdk you added to your project uses AndroidX.
Note: AndroidX and android.support are not compatible.
So you have to either migrate your project to AndroidX or use a support version of Firebase.
Migrate code to use AndroidX
From Refactor option choose Migrate to Androidx.
Sync the project and you should be fine.
Use a Non-Androidx firebase.
Go to Firebase release notes
Find the last version that is before migrating library to AndroidX (For instance Firebase messaging 19 uses androidx and lower versions don't)
TL;DR
Migrate to AndroidX or use a lower version library of Firebase.
In your application tag add tools:replace="android:appComponentFactory"
<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"
>
then gradle.properties add
android.enableJetifier=true
android.useAndroidX=true

Can't run the app after updated the firebase build version

Updated the firebase cloud messaging Gradle file version from 17.4.0 to 19.0.1 failed with Gradle build issue
implementation 'com.google.firebase:firebase-messaging:19.0.1'
implementation 'com.google.firebase:firebase-core:17.0.0'
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:70:5-482:19 to override.```
You are having problem with dependencies that do not depend on AndroidX.
See about migration to AndroidX here.
Explanation: You have some dependency that depends on android support (Old, deprecated), and some dependency that depends on AndroidX. So there is a conflict when merging them.
Force your dependencies to use AndroidX by adding the following to your gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
Also,
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.
Now, see this:
Firebase release notes and mention to AndroidX. The official docs that state you need to use AndroidX in these versions.
Edit, just to add a reminder:
Whenever updating dependencies, specially a major version (the first, most significant number on the version code), read the release-notes. Even more if you are dealing with an already released software. This might save some lives.
You can find detailed error log about your merge issue if you select your manifest file in your project folder then change the bottom tab to "Merge Manifest".
Maybe it can help you to find out more. See attachment.
You cant have a support library and an androidx library. You must either convert to androidx or remove your androidx libs and use normal libs.

Error occured during insertion of AdMob or Firebase Codes in gradle

i have android studio project, when i insert AdMob or Firebase Codes in gradle, see 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:8:1-25:15 to override.
This is my manifest
manifest
This is the gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
}
The new Firebase libraries and the new Google Play Libraries require androidx.
Since you are using these libraries, you are using both support libraries and androidx libraries.
Check the note:
This release is a MAJOR version update and includes breaking changes.
With this release, libraries are migrated from the Android Support Libraries to the Jetpack (AndroidX) Libraries.
The updated libraries will not work unless you make the following changes in your app:
Upgrade com.android.tools.build:gradle to v3.2.1 or later.
Upgrade compileSdkVersion to 28 or later.
Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.
its working after add this code to <application>
tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx"

Undo migration to AndroidX

I've refactored my Android Studio codebase to AndroidX successfully. But it is causing a few problems with some of my libraries.
I need to revert it since the app is going into production soon. How can I do it?
I had gone through the same, Follow the steps to undo the AndroidX Migration:
Remove following lines in gradle.properties:
android.enableJetifier=true
android.useAndroidX=true
Remove AndroidX dependencies in build.gradle of your app and replace them with their equivalent Non AndroidX dependencies:
e.g.
implementation 'androidx.core:core:1.0.0-beta01'
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
Sync Project with Gradle Files
After syncing you may have import errors in java files, you can remove the androidx imports and re add the equivalent non androidx imports
I hope it will help everyone facing migration rollback problem. If you get any conflict issues while performing above steps in Android Studio, try to clean and rebuild the project.
You can simply choose Migrate App to appCompat from Refactor menu in Android Studio.
Also, don't forget to delete these lines from gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
I couldn't simply roll back in version control, because the app I wanted to roll back was androidx from its initial commit, but I was tasked with integrating the app module into a larger project without androidx.
Here's what I did:
Try syncing gradle and inevitably you'll get some kind of error. Here is the first error I saw:
Error: Attribute application#appComponentFactory
value=(androidx.core.app.CoreComponentFactory) from
[androidx.core:core:1.1.0] AndroidManifest.xml:24:18-86 is also
present at [com.android.support:support-compat:28.0.0]
AndroidManifest.xml:22:18-91
value=(android.support.v4.app.CoreComponentFactory)
Take note of the androidx package in the above error.
Run gradlew dependencies inside the module you're trying to migrate back.
Search the output for the androidx package mentioned in the above error. Figure out which of your dependencies from your build.gradle file is bringing in that package, then revert that package to its equivalent support library mapping.
Repeat steps 1-4 until Gradle sync finishes successfully.
Now you need to search all your .java files for androidx and replace each import statement with its support library package name. Tip for this step: turn on "Add unambiguous imports on the fly" in Android Studio preferences and just delete all the androidx imports. Most of them will auto-repopulate with the correct support packages.
Now your project should build successfully, but you'll likely run into runtime crashes due to androidx view components used in layout files.
Search all xml files for androidx and com.google.android.material, and replace each view with its support equivalent name.
Don't forget to fix any compilation issues in your tests, and re-run them to make sure they still all pass.
Do a hard reset on repository which was working before migration to android x.
Delete the node_modules folder, and type npm install.

Manifest Merger fails for appComponentFactory [duplicate]

This question already has answers here:
Android Material and appcompat Manifest merger failed
(35 answers)
Closed 3 years ago.
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
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.
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
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.
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'
Replace in dependencies
from:
implementation 'com.google.android.material:material:1.0.0-rc01'
to:
implementation 'com.android.support:design:28.0.0'
try : replace rc01 >> alpha1 . It's working for me !
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.
Deselecting instant run worked for me. Not sure if it helps for everyone.

Categories

Resources