当我按照Firebase指示进行添加时:
classpath 'com.google.gms:google-services:4.2.0'
到
dependencies
并:implementation 'com.google.firebase:firebase-core:17.0.0'
到
dependencies
上,突然我在dependencies
的这一行上收到一个错误:implementation 'com.android.support:appcompat-v7:27.1.1'
这是错误消息:
Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='animated-vector-drawable', myVersion='27.1.1', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.lifecycle', myArtifactId='lifecycle-viewmodel', myVersion='2.0.0', myPacking='aar', myClassifier='null'} incompatible dependencies less... (⌘F1)
Inspection info:There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).
我该怎么办?为什么在添加Firebase之后会发生这种情况?
最佳答案
(编辑:这是由于某些问题而被删除的原始答案的改进答案。)
Firebase已在最新版本中迁移到AndroidX。意思就是,
AndroidX maps the original support library API packages into the androidx namespace. Only the package and Maven artifact names changed; class, method, and field names did not change.
因此,最新的Firebase版本不再支持旧的支持库。您必须使用以下方法降级Firebase,
implementation 'com.google.firebase:firebase-core:16.0.9'
或迁移您的应用程序以使用如下所述的AndroidX。(无论如何,如果您的应用程序依赖于任何
com.google.android.gms
或com.google.firebase
库,则应为此迁移做准备)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.
使用Android Studio 3.2及更高版本,迁移变得更加容易。从菜单栏中选择 Refactor>将迁移到AndroidX,我们可以迁移到AndroidX。
而且任何Maven依赖项都可以按以下方式处理,
Maven dependencies that have not been migrated to the AndroidX namespace, the Android Studio build system also migrates those dependencies for you when you set the following two flags to true in your gradle.properties file:
android.useAndroidX=true android.enableJetifier=true
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.
关于android - Android:添加firebase要求时,build.gradle错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56794211/