首页 > 解决方案 > 将firebase添加到android时出现AndroidX依赖错误

问题描述

我正在开发一个 android 项目,当我尝试将 firebase 依赖项添加到项目后发生构建错误时。我曾尝试迁移到 appCompat,但没有成功。

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

未添加 firebase 的依赖项如下:

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'

请帮助解决上述问题。

标签: androidfirebaseandroid-gradle-pluginandroid-appcompatandroidx

解决方案


android.useAndroidX=true

Android 插件使用适当的 AndroidX 库而不是支持库。

android.enableJetifier=true

Android 插件通过重写其二进制文件自动迁移现有的第三方库以使用 AndroidX

在gradle.properties文件中添加这两行。

然后清理项目并重建项目。

可能你的问题会得到解决。如果不让我知道。

您当前使用的基于 Android 的库应该迁移到 Androidx。

我建议您在 Androidx 中迁移您的项目。您很容易获得更多帖子如何将 android 迁移到 androidx 我的项目。


推荐阅读