jetifier

The standalone Jetifier tool migrates support-library-dependent libraries torely on the equivalent AndroidX packages instead. The tool lets you migrate anindividual library directly, instead of using the Android gradle plugin bundledwith Android Studio.

Note: Before you begin the migration, you should update your library to useversion 28.0.0 of the support library.

Install jetifier

To install Jetifier, download the zipfileand extract it. Your device must have Java version 1.8 installed.

Usage

To process a library, pass the path to the current library and the path to theoutput file that the tool should create. Jetifier supports JAR, AAR, and ZIPfiles, including nested archives.

  1. ./jetifier-standalone -i <source-library> -o <output-library>

Options

OptionRequired?Description
-i, —input <path>yesPath to input library (JAR, AAR, or ZIP)
-o, —output <path>yesPath to the output file. If the file already exists, jetifier overwrites it.
-c, —config <path>noPath to optional custom config file.
-l, —log <level>noLogging level. Allowed values are:
- error
- warning
- info
- verboseIf not specified, defaults to "warning".
-rnoOperate in reverse mode ("de-jetification").

Example

The following example runs the utility on the library libraryToProcess.aar (inthe current directory) and writes the output to result.aar in the samedirectory:

  1. ./jetifier-standalone -i libraryToProcess.aar -o result.aar

Usage Notes

Jetifier migrates Java, XML, POM and ProGuard references that point toandroid.support. packages, changing them so they point to the correspondingandroidx. packages.

Since ProGuard wildcards for android.support. do not always map directly toandroidx. packages, Jetifier produces all eligible substitutions.

If there is a type in an android.support.* package that does not come from anysupport library artifact, Jetifier still migrates the type as long as there is amapping for it. However, this migration is not guaranteed to work, as theremight not be mapping rules general enough to cover all the custom types.

Advanced usage

The Jetifier utility supports some advanced use cases.

Reverse mode

If you pass the -r flag, the utility runs in reverse mode. In this mode, theutility converts AndroidX APIs to the support library equivalents, instead ofthe other way around. Reverse mode is useful, for example, if you are developinglibraries that use AndroidX APIs, but also need to distribute versions that usethe support library.

Example

The following example runs the utility in reverse mode on the librarymyAndroidXLib.aar (in the current directory) and writes the output tosupportLibVersion.aar in the same directory:

  1. ./jetifier-standalone -r -i myAndroidXLib.aar -o supportLibVersion.aar

Custom config file

The Jetifier tool uses a config file to map support library classes to theirAndroidX equivalents. If necessary, you can make a custom config file thatalters this mapping. You can even add new classes to the mapping that are notactually members of the support library; for example, you might modify themapping to replace one of your own classes with a successor class written to useAndroidX.

To use a custom config file, first extract the file default.generated.configfrom the utility's jetifier-core-*.jar file and save it. Make any necessaryedits to your copy of the config file, and pass your file to the utility withthe -c flag. For example:

  1. ./jetifier-standalone -i libraryToProcess.aar -o result.aar -c myCustomMapping.config