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

查看:530
本文介绍了我可以在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 -one交换. (例如,您的Lottie依赖项将从支持更改为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/features/):

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.
  • android.useAndroidX: When set to true, this flag indicates that you want to start using AndroidX from now on. If the flag is absent, Android Studio behaves as if the flag were set to false.
  • android.enableJetifier: When set to true, this flag indicates that you want to have tool support (from the Android Gradle plugin) to automatically convert existing third-party libraries as if they were written for AndroidX. If the flag is absent, Android Studio behaves as if the flag were set to 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)仍存在一些问题:

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天全站免登陆