I have next grade
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.material:material:1.0.0-rc01'
}
But when I want to build app I get next log:
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.
Okey! Go to manifest and do it:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.chopcode.myapplication">
<application
tools:replace="android:appComponentFactory"
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">
</application>
</manifest>
Then I get this error in my Logcat:
Manifest merger failed with multiple errors, see logs that I have Linked with it
I had similar problem. Added two lines in gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
These two lines automatically resolved my dependency conflicts between google's files and third party dependencies. Here's the link to follow: https://developer.android.com/topic/libraries/support-library/androidx-overview#new-project
I faced same error when i try to add Kotlin-KTX library to my project.
I try to AndroidX migration, and problem fixed!
Reason of Fail
You are using material library which is part of AndroidX.
If you are not aware of AndroidX, please go through this answer.
One app should use either AndroidX or old Android Support libraries.
That's why you faced this issue.
For example -
In your gradle, you are using
com.android.support:appcompat-v7 (Part of old --Android Support Library--)
com.google.android.material:material (Part of AndroidX) (AndroidX build artifact of com.android.support:design)
Solution
So the solution is to use either AndroidX or old Support Library. I recommend to use AndroidX, because Android will not update support libraries after version 28.0.0. See release notes of Support Library.
Just migrate to AndroidX.Here is my detailed answer to migrate to AndroidX. I am putting here the needful steps from that answer.
Before you migrate, it is strongly recommended to backup your project.
Existing project
Android Studio > Refactor Menu > Migrate to AndroidX...
It will analysis and will open Refractor window in bottom. Accept changes to be done.
New project
Put these flags in your gradle.properties
android.enableJetifier=true
android.useAndroidX=true
Check #Library mappings for equal AndroidX package.
Check #Official page of Migrate to AndroidX
What is Jetifier?
In my case, this is working perfectly..
I have added below two line codes inside manifest file
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Credit goes to this answer.
Simple Solutions - migrate into AndroidX
in the gradle.properties, just add below two scripts
android.useAndroidX=true
android.enableJetifier=true
What was the reason ↓
All packages in AndroidX live in a consistent namespace starting with the string androidx. The Support Library packages have been mapped into the corresponding androidx.* packages. For a full mapping of all the old classes and build artifacts to the new ones, see the Package Refactoring page.
Please see the Package Refactoring page
Just change "rc01" in first and last line inside dependencies to "alpha1"
This is working for me
Just remove the android.support dependancy
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Quoting From Material Guidelines
If you don’t want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0-alpha3 dependency.
Note: You should not use the com.android.support and com.google.android.dependencies in your app at the same time.
Just removing this dependency works fine
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
Here is complete dependencies example
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
As of Android P, the support libraries have been moved to AndroidX
Please do a refactor for your libs from this page.
https://developer.android.com/topic/libraries/support-library/refactor
See This Image and Add This line in your android AndroidManifest.xml
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Please go to Refactor->Migrate->Migrate to Android X.
Please add this to your gradle.properties file:
android.enableJetifier=true
android.useAndroidX=true
And perform Sync.
Add these lines inside in AndroidManifest.xml file.
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
just add these two lines of code to your Manifest file
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Migrate to androidX if it an existing project. If it is new project add these two flags to Gradle.propeties
android.enableJetifier=true
android.useAndroidX=true
for more detail steps https://developer.android.com/jetpack/androidx
or check this What is AndroidX?
Follow these steps:
Goto Refactor and Click Migrate to AndroidX
Click Do Refactor
Only If you don't want to use androidx
So in my case, I am using a library that was using androidx but I am not using androidx so when I downgraded that library version the problem was resolved.
In my Case:
implementation 'com.github.turing-tech:MaterialScrollBar:13.+'
the above-mentioned library makes problem 13.+ will automatically get a new version of the library which using androidx. So I downgraded library version to:
implementation 'com.github.turing-tech:MaterialScrollBar:13.2.5'
And the problem was resolved.
This issue mainly happened for old dependencies.
There have 2 solution:
First one:
Update all old dependencies and ClassPaths from Project level gradle files.
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
Second one:
Your project Migrate to AndroidX
From Android Studio Menu -> Refanctor -> Migrate to AndroidX
Thanks, let me know if anyone help from this answer.
Finally found a quick and easy solution by adding two lines in the android/build.gradle file.
googlePlayServicesVersion = "16.+"
firebaseVersion = "17.6.0"
Please follow this 100% correct.
Its all about the library versions compatibility
I was facing this strange bug couple of 2 hours.
I resolved this error by doing these steps
hange your build.gradle dependencies into
implementation 'com.google.android.gms:play-services-maps:17.0.0'
to
implementation 'com.google.android.gms:play-services-maps:15.0.0'
All I did was go to the "Refactor" option on the top menu.
Then select "Migrate to AndroidX"
Accept to save the project as a zip file.
Please update Android Studio as well as Gradle to ensure no problems are encountered.
Create new project and compare your build.gradle files and replaced all
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
and other dependencies with the same as were in a new project
someting like that
implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'androidx.core:core-ktx:1.0.0-alpha3'
And then fixed imports to use androidx in kotlin files.
If you do not intend to migrate to AndroidX follow the below steps
In terminal type gradlew app:dependencies
After dependencies are shown in the window press Ctrl+f and type androidX
You will find all the dependencies which are using androidx lib internally you may have to downgrade that or use alternative for that to ensure it is no longer using androidX libs internally.
1.Added these codes to at the end of your app/build.gradle:
configurations.all {
resolutionStrategy.force 'com.android.support:support-v4:28.0.0'
// the above lib may be old dependencies version
}
2.Modified sdk and tools version to 28:
compileSdkVersion 28
buildToolsVersion '28.0.3'
targetSdkVersion 28
3.In your AndroidManifest.xml file, you should add two line:
<application
android:name=".YourApplication"
android:appComponentFactory="AnyStrings"
tools:replace="android:appComponentFactory"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
Or Simply
Go to Refactor (Studio -> Menu -> Refactor)
Click the Migrate to AndroidX. it's working
it's working.
First of all be sure to add this line in manifest tag
xmlns:tools="https://schemas.android.com/tools"
Then add tools replace your suggested one in Android studio
Go to Refactor (Image )
Click the Migrate to AndroidX. it's working
it's working.
Try this
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
Rebuild your project.
I had this same problem for three days.
It is like android wants us to either use Kotlin Or AndroidX, they are doing away with Android.
But this is how I solved it.
I migrated my project to AndroidX. This does not bring in any errors related to this issue in question, It updates files respectively. No method, class or variable name needs to be changed in your application.
NB: You must be using the latest Libraries (build.grudle file) in the latest stable version of android studio 3.4.1
I don't know this is the proper answer or not but it worked for me
Increase Gridle Wrapper Property
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
and Build Gridle to
classpath 'com.android.tools.build:gradle:3.4.2'
its showing error because of the version.
Change proguardFile in build.gradle (Module: app) to the following
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
instead of
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
This worked for me
For solving this issue i would recommend to define explicitly the version for the ext variables
at the android/build.gradle at your root project
ext {
googlePlayServicesVersion = "16.1.0" // default: "+"
firebaseVersion = "15.0.2" // default: "+"
// Other settings
compileSdkVersion = <Your compile SDK version> // default: 23
buildToolsVersion = "<Your build tools version>" // default: "23.0.1"
targetSdkVersion = <Your target SDK version> // default: 23
supportLibVersion = "<Your support lib version>" // default: 23.1.1
}
reference
https://github.com/zo0r/react-native-push-notification/issues/1109#issuecomment-506414941
I'm also facing the same issue,
for your android studio, you just change the android Gradle plugin version 3.3.2
and Gradle version is 5.1.1
Related
I am working on an android project, When I tries to add firebase dependency to project following Build error occurs. I have tried migrating to appCompat but didnt workded.
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.The following AndroidX dependencies are detected: androidx.versionedparcelable:versionedparcelable:1.0.0, androidx.fragment:fragment:1.0.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.core:core:1.0.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.loader:loader:1.0.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.viewpager:viewpager:1.0.0, androidx.collection:collection:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.lifecycle:lifecycle-common:2.0.0, androidx.arch.core:core-common:2.0.0, androidx.annotation:annotation:1.1.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.lifecycle:lifecycle-viewmodel:2.0.0, androidx.lifecycle:lifecycle-livedata-core:2.0.0, androidx.arch.core:core-runtime:2.0.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.lifecycle:lifecycle-runtime:2.0.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.print:print:1.0.0
dependencies added without firebase are as follows:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
Please help to resolve above issue.
android.useAndroidX=true
The Android plugin uses the appropriate AndroidX library instead of a Support Library.
android.enableJetifier=true
The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries
Add both line in your gradle.properties file.
Then clean project and rebuild project.
May be your problem will be solved.
If not let me know.
You are currently using Android based library should be migrated to Androidx.
I suggest you migrate your project in Androidx.
You easily got more post How to migrate android to androidx my project.
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
I updated 'android.support:appcompat-v7' to 28.0.0.
But it brought an error from the build.
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:5-23:19 to override.
Then I get this error in my Logcat:
Manifest merger failed
my app.gradle:
configurations.all {
resolutionStrategy.force 'com.android.support:design:28.0.0'
resolutionStrategy.force "com.android.support:support-v4:28.0.0"
resolutionStrategy.force "com.android.support:support-media-compat:28.0.0"
}
...
dependencies {
implementation 'com.android.support:multidex:1.0.1'
// Our dependencies
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}
how do I fix it?
I need your solutions.
Thank you in advance.
Upgrading 'react-native-device-info' to version 2.1.2 fixed the error for me. See github.com/facebook/react-native/issues/25294#issuecomment-503024749
In short: the library used "services-gcm:+" as a dependency, and the latest gcm version caused this problem.
The root cause is related migration to Androidx, google play service updated to androidX
Thanks to MR03web This problem belongs to react-native-device-info? best option is to upgrade react-native-device-info using
yarn upgrade react-native-device-info#2.1.2
cd android && gradlew clean
react-native run-android
or if you don't want to upgrade you should exclude com.google.android.gms from react-native-device-info like this. Thanks
implementation(project(":react-native-device-info"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-gcm:16.0.0"
Add the following to your gradle.properties then clean/rebuild
googlePlayServicesVersion=16.1.0
firebaseVersion=17.6.0
I found a solution through my search by referring to #MehulSolanki answer.
I add
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
in my on AndroidManifest.xml
and update com.android.tools.build:gradl:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
And add this in your gradle.properties file
android.useAndroidX=true
android.enableJetifier=true
ERROR: [TAG] Failed to resolve variable '${animal.sniffer.version}'
ERROR: [TAG] Failed to resolve variable '${junit.version}'
In case of above error
File -> Invalidate Caches / restart
Build -> Clean project
error: package android.support.annotation does not exist
error: cannot find symbol class Nullable
In case of above error
Add implementation 'androidx.annotation:annotation:1.1.0'
change import android.support.annotation.Nullable; => androidx.annotation.Nullable;
change import android.support.annotation.NonNull; => androidx.annotation.NonNull;
Compile version and target version should be 28.
Add 'tools:replace="android:appComponentFactory"' in your AndroidManifest.xml inside <application> tag
Your AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ru.chopcode.myapplication">
<application
tools:replace="android:appComponentFactory"
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">
</application>
Downgrade Google Play service version. In android/app/build.gradle change
compile 'com.google.android.gms:play-services-<service_name>:+'
to
compile 'com.google.android.gms:play-services-<service_name>:16.0.0'
So in my case < sevice_name > was location. But in someone's else case it may be any other Google Play Service (like in list here http://www.androiddocs.com/google/play-services/setup.html).
After spending a whole day on this issue. Finally, I have resolved this issue.
I got that error from react-native-device-info and react-native-fast-image library.
I just remove that library from package.json file and then install
"react-native-device-info": "^2.1.2",
"react-native-fast-image": "^6.0.3" this latest version
I have used below gradle version
classpath 'com.android.tools.build:gradle:3.3.1'
I have used below properties version
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
I have used below versions
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
This answer should help most people. If it still does not then the way to solve this (which is not that good) is that you open the android project in android studio. That should fetch all the gradle files. On the right side the view should be android.
From here just check each gradle build file for a + sign ahead of google play services or firebase services or any such library. This has also been explained in this answer.
After which you either change it like explained in the answer above.
like so.
implementation(project(":react-native-admob"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-ads:16.0.0"
Or you provide a variable if the library is using one or as a last resort change it there itself.
The reason I put it here is so that any newbie who is sick of this error which randomly appeared out of nowhere all of a sudden can solve it effectively and not...die. lol.
I had the same problem, just upgrade react-native-device-info and run the following command
npm upgrade react-native-device-info#latest
react-native run-android
According to #Frank's answer the library used services-gcm:+ as a dependency, and the latest gcm version caused this problem.
And I had used :react-native-admob in my project. So I just change the following lines in android/app/build.gradle
From:
implementation project(':react-native-admob')
TO :
implementation(project(":react-native-admob"), {
exclude group: "com.google.android.gms"
})
implementation "com.google.android.gms:play-services-ads:16.0.0"
If you are not using react-native-device-info, but have the same error, its probably another library in your project.
Use this to find the library in question:
cd your-react-native-project/android
./gradlew app:dependencies > deps.txt
Then inspect the deps.txt file for keyword "androidx". Then you can quickly find which native module is using it.
In my case it was react-native-camera, for which solution above was good but not enough so I had to add this to local.properties:
firebaseVersion=17.6.0
googlePlayServicesVersion=16.1.0
googlePlayServicesVisionVersion=16.2.0
EDIT:
After these fixes, running ./gradlew app:dependencies > deps.txt and searching for "androidx" returned no results - this is what we are looking for.
After running clean on the project, build worked.
Upgrading react-native-device-info to version 2.1.2 Fix my problem
Google play services breaking changes. See Release Notes.
The simple way to resolve this issue is just changing the version of Google play services.
Change all com.google.android.gms:play-services-* dependencies to version 16
I recently updated my Android Studio (and I'm pretty sure the Gradle version), and now I've been getting a bunch of errors when trying to compile my project. Here's the one that is plaguing me at the moment:
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:26.1.0)
This is followed by lots of similar ones.
I tried removing all uses of com.android.support in favor of androidx (see here for what I was using the replace things), but com.android.support libraries are still being used, even when I delete the libraries (they're just remade once I try to compile again).
Here's a link to the full error I get.
Add these lines to your gradle.properties
android.useAndroidX=true
android.enableJetifier=true
If gradle.properties is absent, create the file in the root directory of your project.
It looks like you have some support relics anywhere in your dependencies, maybe from a lib? To investigate and see the dependencies tree, please run:
./gradlew :yourApp:dependencies
and then you see from where it comes.
In your app build.gradle you are using a mix of old support library and new support library artifacts. Remove one of them from your build.gradle to resolve this issue.
Old artifact: com.android.support:support-compat
Corresponding new artifact: androidx.core:core:1.0.0
See this page for more information on migrating to AndroidX.
Like others says, the solution is to migrating to AndroidX, it works for me. However, it isn´t an easy way and it requires a bit of pacience... These are the steps that I did:
First, is very important that you do all this changes in a different branch or you make a backup of your project.
You need to have the Android Gradle Plugin Version 3.5.1. So, in build.gradle set:
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
}
Migrate to AndroidX using Android Studio Tool : Refactor --> Migrate to AndroidX...
When it finishes, it has done all pertinents modification, but posibly you can´t deploy the project correctly because you find any errors. These are the problems that I found and the solutions:
If you use Kotlin, in build.gradle set:
buildscript {
ext.kotlin_version = '1.3.10'
}
and
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
If you use destination method, add "file" parameter: destination file("$reportsDir/checkstyle/checkstyle.xml")
If you use Butterknife, use 10.0.0 version
Finally, Build --> Clean Project and Build --> Rebuild Project
This solution from here worked the best for me. Migrating to androidX
https://developer.android.com/jetpack/androidx/migrate
With Android Studio 3.2 and higher, you can migrate an existing
project to AndroidX by selecting Refactor > Migrate to AndroidX from
the menu bar.
The refactor command makes use of two flags. By default, both of them
are set to true in your gradle.properties file:
android.useAndroidX=true The Android plugin uses the appropriate
AndroidX library instead of a Support Library.
android.enableJetifier=true The Android plugin automatically migrates
existing third-party libraries to use AndroidX by rewriting their
binaries.
If you face any issue regarding duplicate classes after using Facebook mediation and google ad libraries so follow these steps:
1- Add this in build.gradle(Module) in Top
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.gms.google-services'
2- Add this in build.gradle(Module) -> android
packagingOptions {
exclude "META-INF/DEPENDENCIES"
}
3- Add this in build.gradle(Module) -> dependencies
//firebase bom
implementation platform('com.google.firebase:firebase-bom:29.2.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging:23.0.1'
//ADS
def ads_version = "20.6.0"
implementation "com.google.android.gms:play-services-ads:$ads_version"
//facebook ads
implementation 'com.google.ads.mediation:facebook:6.8.0.0'
4- Add this in build.gradle(Project )-> buildscript-> dependencies
classpath "com.android.tools.build:gradle:7.0.4"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
5- Add this in gradle.wrapper.propertise
#Wed Dec 16 15:32:03 PKT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.0.2-bin.zip
Let's say i have a public library module published to Maven Central and it is using the following dependencies:
implementation 'com.android.support:recyclerview-v7:28.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Will this library work with no problems on Android X based projects?
Google has released a tool called Jetifier which migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead, so your libiary should work when Jetifier is enabled.
To enable Jetifier, make sure compileSdkVersion is set to API 28 or above and add the following lines in gradle.properties:
android.useAndroidX=true
android.enableJetifier=true