Skip to main content

Google re-branded the support Android libraries to AndroidX




It is important to note, you cannot mix AppCompat and Jetpack in the same project. You must convert everything to use Jetpack if you want to upgrade.

The support library artifacts are being deprecated and all future development is going into AndroidX, so there's no avoiding this migration.

Alan Viverette sums this up nicely:
“There won’t be a 29.0.0, so Android Q APIs will only be in AndroidX”

The stable release of 28.0.0 will be the final feature release packaged as android.support. All subsequent feature releases will only be made available as androidx-packaged artifacts.

Below tips will give you a clearer transition path.

The current version of AppCompat (v28.x) is exactly the same as AndroidX (v1.x). In fact, the AppCompat libraries are machine generated by changing maven coordinates and package names of the AndroidX codebase.

For example, android.support.v7.app.AppCompatActivity is now androidx.appcompat.app.AppCompatActivity

For a complete listing of mappings from 28.0.0-alpha1 (android.support) to 1.0.0-alpha1 (androidx).
https://developer.android.com/jetpack/androidx/migrate#artifact_mappings

Steps to use AndroidX in new project:

You need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the following Android Gradle plugin flags to true in your gradle.properties file.

android.useAndroidX: When set to true, the Android plugin uses the appropriate AndroidX library instead of a Support Library. The flag is false by default if it is not specified.
android.enableJetifier: When set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. The flag is false by default if it is not specified.

Steps to migrate your existing project to androidX


1. Upgrade your app to latest Support libs

2. Migrate an existing project using Android Studio
With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting
Refactor > Migrate to AndroidX from the menu bar.



3. If you have any Maven dependencies that have not been migrated to the AndroidX namespace, the Android Studio build system also migrates those dependencies for you when you set the following two flags to true in your gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

To migrate an existing project that does not use any third-party libraries with dependencies that need converting,
you can set the android.useAndroidX flag to true &
android.enableJetifier flag to false.

If you depend on a library that references the older Support Library, Android Studio will update that library to reference androidx instead via dependency translation. Dependency translation is automatically applied by the Android Gradle Plugin 3.2.0-alpha14, which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts.

Challenges:

Butter Knife. It generates classes that contains references to support annotations (e.g. android.support.annotation.UiThread). These imports cannot be jetified to AndroidX (since it's source code), so you'll get compiler errors instead.

Thankfully, they have versions that support AndroidX now (many thanks to Square for making AndroidX-friendly artifacts)

You will have to manually migrate in case of errors.

So please update your third-party libraries before migrating to AndroidX

References:

https://developer.android.com/jetpack/androidx/migrate#migrate



Comments

Popular posts from this blog

Short explanation on Gradle, minSdkVersion, maxSdkVersion, compileSdkVersion and targetSdkVersion in Android

Gradle : The Android build system compiles app resources and source code, and packages them into APKs that you can test, deploy, sign, and distribute. Android Studio uses Gradle . The Android plugin for Gradle works with the build toolkit to provide processes and configurable settings that are specific to building and testing Android applications. Gradle and the Android plugin run independent of Android Studio. Gradle architecture is shown below. Example: android { compileSdkVersion 27 buildToolsVersion “26.0.2” defaultConfig { applicationId “com.example.checkyourtargetsdk" minSdkVersion 15 targetSdkVersion 27 versionCode 1 versionName “1.0” } } minSdkVersion : minSdkVersion is the lower bound for your app . The minSdkVersion is one of the signals the Google Play Store uses to determine which of a user’s devices an app can be installed on.  your app’s minSdkVersion must be at least as high as your dependencies’ minSdkVe

Android Beginners Guide

                                                                                                               Android Operation System: Android is an operating system based on Linux with a Java programming interface. It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik Virtual Machine - DVM). Android is created by the Open Handset Alliance which is lead by Google. Android uses a special virtual machine, e.g. the Dalvik Virtual Machine. Dalvik uses special bytecode. Therefore you cannot run standard Java bytecode on Android. Android provides a tool "dx" which allows to convert Java Class files into "dex" (Dalvik Executable) files. Android applications are packed into an .apk (Android Package) file by the program "aapt" (Android Asset Packaging Tool) To simplify development Google provides the Android Development Tools (ADT) for Eclipse. The ADT performs automatically the conversion f