我知道,androidx and support dependency causing multidex error
我们不能同时使用androidx和android支持.所以我完全迁移到androidx.但我的一个依赖lib使用了android支持“lottie”.
我们不能同时使用androidx和android支持.所以我完全迁移到androidx.但我的一个依赖lib使用了android支持“lottie”.
在上述情况下我们能做些什么?我应该从我的项目中删除’lottie’吗?
下面是我的傻瓜
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,这将基本上与AndroidX-1交换项目依赖项中的Android支持库依赖项. (例如,您的Lottie依赖项将从Support更改为AnroidX)
从Android Studio文档(https://developer.android.com/studio/preview/features/):
The Android Gradle plugin provides the following global flags that you
can set in your gradle.properties file:
- 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的先决条件:
>你必须至少使用Android Studio 3.2
要启用jetifier,请将这两行添加到gradle.properties文件中:
android.useAndroidX=true android.enableJetifier=true
最后,请查看AndroidX的发行说明,因为jetifier在某些库中仍存在一些问题(例如Dagger Android):https://developer.android.com/topic/libraries/support-library/androidx-rn