Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use library that used android support with Androidx projects.

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".

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

below is my gradle

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"     } 
like image 608
Hitesh Dhamshaniya Avatar asked Aug 27 '18 06:08

Hitesh Dhamshaniya


People also ask

Is AndroidX backwards compatible?

Is AndroidX backwards compatible to earlier versions of Android? The short answer is yes. The new AndroidX naming design is just that, a design. The support libraries are built for backwards compatibility and so are the AndroidX libraries.

What is the use of Android support library?

The Android Support Library package is a set of code libraries that provide backward-compatible versions of Android framework APIs as well as features that are only available through the library APIs. Each Support Library is backward-compatible to a specific Android API level.

What is the difference between AndroidX and Android support?

AndroidX is a major improvement to the original Android Support Library, which is no longer maintained. androidx packages fully replace the Support Library by providing feature parity and new libraries.

Is AndroidX a support library?

Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components. You can continue to use the support library.


1 Answers

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)

From the Android Studio Documentation (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.

Precondition for Jetifier:

  • you have to use at least Android Studio 3.2

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

android.useAndroidX=true android.enableJetifier=true 

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

like image 158
Christopher Avatar answered Oct 12 '22 15:10

Christopher