我可以使用在 Androidx 项目中使用了 android 支持的库吗? [英] Can I use library that used android support with Androidx projects.

查看:42
本文介绍了我可以使用在 Androidx 项目中使用了 android 支持的库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,androidx 和支持导致 multidex 错误的依赖我们不能同时使用 androidx 和 android 支持.所以我完全迁移到 androidx.但是我的一个依赖库使用了 android 支持lottie".

I know, androidx and support dependency causing multidex error We can not use androidx and android support at a same time. So I totally migrate to androidx. but one of my dependency lib used android support "lottie".

遇到以上情况我们该怎么办?我是否应该从我的项目中删除lottie".

What can we do in above situation? Should I remove 'lottie' from my project.

下面是我的毕业证

defaultConfig {
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }

    ext{
    lottieVersion = "2.5.4"
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    def androidx = "1.0.0-rc01"
    api "androidx.constraintlayout:constraintlayout:1.1.2"
    api "androidx.appcompat:appcompat:$androidx"
    api "androidx.recyclerview:recyclerview:$androidx"
    api "androidx.cardview:cardview:$androidx"
    api "androidx.core:core-ktx:$androidx"
    api "com.google.android.material:material:1.0.0-rc01"
    implementation "com.google.code.gson:gson:2.8.5"
    implementation "androidx.multidex:multidex:2.0.0"
    implementation "com.airbnb.android:lottie:$lottieVersion"
    }

推荐答案

您可以在您的项目上启用 Jetifier,这将基本上交换您的 Android Support Library 依赖项AndroidX 的项目依赖项.(例如,您的 Lottie 依赖项将从 Support 更改为 AnroidX)

You can enable Jetifier on your project, which will basically exchange the Android Support Library dependencies in your project dependencies with AndroidX-ones. (e.g. Your Lottie dependencies will be changed from Support to AnroidX)

来自 Android Studio 文档 (https://developer.android.com/studio/preview/功能/):

From the Android Studio Documentation (https://developer.android.com/studio/preview/features/):

Android Gradle 插件提供了以下全局标志,您可以可以在你的 gradle.properties 文件中设置:

The Android Gradle plugin provides the following global flags that you can set in your gradle.properties file:

  • android.useAndroidX:当设置为 true 时,此标志表示您希望从现在开始使用 AndroidX.如果没有国旗,Android Studio 的行为就像将标志设置为 false.
  • android.enableJetifier:当设置为 true 时,这个标志表明你想要有工具支持(来自 Android Gradle 插件)到自动转换现有的第三方库,就好像它们是为 AndroidX 编写.如果该标志不存在,Android Studio 的行为如下如果该标志设置为 false.

Jetifier 的先决条件:

Precondition for Jetifier:

  • 您必须至少使用 Android Studio 3.2

要启用 jetifier,请将这两行添加到您的 gradle.properties 文件中:

To enable jetifier, add those two lines to your gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

最后,请查看AndroidX的发行说明,因为jetifier在某些库(例如Dagger Android)中仍然存在一些问题:https://developer.android.com/topic/libraries/support-library/androidx-rn

Finally, please check the release notes of AndroidX, because jetifier has still some problems with some libraries (e.g. Dagger Android): https://developer.android.com/topic/libraries/support-library/androidx-rn

这篇关于我可以使用在 Androidx 项目中使用了 android 支持的库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆