The standalone Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. The tool lets you migrate an individual library directly, instead of using the Android gradle plugin bundled with Android Studio.
Install jetifier
To install Jetifier, download the zip file and 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 the output file that the tool should create. Jetifier supports JAR, AAR, and ZIP files, including nested archives.
./jetifier-standalone -i <source-library> -o <output-library>
Options
Option | Required? | Description |
---|---|---|
-i, --input <path> | yes | Path to input library (JAR, AAR, or ZIP) |
-o, --output <path> | yes | Path to the output file. If the file already exists, jetifier overwrites it. |
-c, --config <path> | no | Path to optional custom config file. |
-l, --log <level> | no | Logging level. Allowed values are:
|
-r | no | Operate in reverse mode ("de-jetification"). |
Example
The following example runs the utility on the library libraryToProcess.aar
(in
the current directory) and writes the output to result.aar
in the same
directory:
./jetifier-standalone -i libraryToProcess.aar -o result.aar
Usage Notes
Jetifier migrates Java, XML, POM and ProGuard references that point to
android.support.*
packages, changing them so they point to the corresponding
androidx.*
packages.
Since ProGuard wildcards for android.support.*
do not always map directly to
androidx.*
packages, Jetifier produces all eligible substitutions.
If there is a type in an android.support.*
package that does not come from any
support library artifact, Jetifier still migrates the type as long as there is a
mapping for it. However, this migration is not guaranteed to work, as there
might 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, the
utility converts AndroidX APIs to the support library equivalents, instead of
the other way around. Reverse mode is useful, for example, if you are developing
libraries that use AndroidX APIs, but also need to distribute versions that use
the support library.
Example
The following example runs the utility in reverse mode on the library
myAndroidXLib.aar
(in the current directory) and writes the output to
supportLibVersion.aar
in the same directory:
./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 their AndroidX equivalents. If necessary, you can make a custom config file that alters this mapping. You can even add new classes to the mapping that are not actually members of the support library; for example, you might modify the mapping to replace one of your own classes with a successor class written to use AndroidX.
To use a custom config file, first extract the file default.generated.config
from the utility's jetifier-core-*.jar
file and save it. Make any necessary
edits to your copy of the config file, and pass your file to the utility with
the -c
flag. For example:
./jetifier-standalone -i libraryToProcess.aar -o result.aar -c myCustomMapping.config