155

What is Jetifier? For example, to create a new project using the androidx-packaged dependencies, this new project needs to add the following line to the gradle.properties file:

android.enableJetifier=true 

So what does it mean - "enable jetifier"?

1
  • 55
    IIRC, Jetifier is an undocumented bit of Googly technology that is supposed to automatically convert transitive dependencies to use AndroidX libraries. For example, suppose that you have implementation "com.commonsware.cwac:document:0.3.0" in your dependencies. That library version has a transitive dependency on com.android.support:support-annotations:27.0.2. However, you want to be using androidx.annotation:annotation as part of using other AndroidX dependencies. Jetifier would somehow update com.commonsware.cwac:document to use androidx.annotation:annotation. Commented Aug 3, 2018 at 22:24

6 Answers 6

116

This is assuming that you are familiar with AndroidX. If not, please see this post.

Jetifier will convert support libraries of all your dependencies to AndroidX automatically, if you don't set it to true then your project will have both, the support (deprecated after 28.0.0 version) and AndroidX package, which is redundant.

For example, if you have PhotoView.java in your dependency that uses support library AppCompatImageView:

import android.support.v7.widget.AppCompatImageView; 

This class is now moved to the androidx package, so how will PhotoView get AndroidX AppCompatImageView? App still runs in device.

What made this work? Jetifier, which converts all support packages of the dependency at build time.

Jetifier will convert android.support.v7.widget.AppCompatImageView to androidx.appcompat.widget.AppCompatImageView while building the project.

Enabling Jetifier is important when you migrate from Support Libraries to AndroidX.

Your code may show compile time errors after enabling Jetifier while using dependency classes which you can remove by deleting .idea and .gradle, and re-syncing project.

image2

image1

Sign up to request clarification or add additional context in comments.

3 Comments

You can get rid of the compile-time errors by deleting .idea/libraries and re-syncing Gradle.
I think Jetifier works at build time and not at runtime as mentioned here. You can either use android.enableJetifier=true on gradle or use the standalone jetifier tool developer.android.com/studio/command-line/jetifier to migrate to androidx. Both these options replace package names at build time so the old support libraries are not even part of the packaging.
This is the best answer. +1
87

This year's Google I/O (18), Google has announced Jetpack which is set/collection of libraries to make developer's life easier.

Jetpack includes previously introduced Android architecture components (ViewModel, Room, Paging, LiveData etc.) as well as newly introduced architecture components like WorkManager, Navigation. Apart from this Jetpack also has other set of libraries like AndroidX, AndroidKTX etc.

AndroidX is new package structure for Android support libraries like support, databinding, design etc.

e.g. now on wards developers will use androidx.databinding. instead of android.databinding. while importing libraries in our projects

This enables Google to add SemVer or Semantic Versioning in there library packages. For developers, this means we don't have to use same support library version for all support libraries. Every support or better to say AndroidX library will maintain its own versioning.

Another advantages for developers is that we don't have to care about maintaining same version for all support library in our project.

About Jetifier, it converts all support package of dependency at build time. As per official documentation of Jetifier

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.

To use AndroidX in a project we have to set targetSdkVersion for our project to 28 and add following 2 lines in gradle.properties file.

android.useAndroidX=true android.enableJetifier=true 

I hope this will answer your query.

EDIT

This link has mapping of all support library component with their AndroidX counter part.

Also please refer This blog for detailed explanation about AndroidX

2 Comments

You're not really answering the question "What is Jetifier?", just taking about AndroidX and Jetpack.
@DavidMiguel I have provided answer to main question asked which is what does it mean - "enable jetifier"?. Although if you think my answer is partial, I will update my answer accordingly.
14

Jetifier helps in migrating an android project to AndroidX.

Jetifier helps in making 3rd party library compatible with your AndroidX project.

If you're not using any 3rd party library in your android project, then you don't need to use Jetifier because Jetifier helps only in "making 3rd party library" compatible with your project in case you're migrating to AndroidX. So to make your project use Jetifier, you write below code in gradle.properties.

android.enableJetifier=true android.useAndroidX=true 

If you're not migrating to AndroidX and using the previous way of using Android libraries(e.g: com.android.support), then these 3rd party libraries need not be made compatible as these 3rd party libraries are already compatible with the previous way of using Android libraries. In that case, you don't need to use Jetifier, So now, you don't need to write lines given above or you can simply write as below to change the values in future to move to androidx:-

android.enableJetifier=false android.useAndroidX=false 

Comments

7

Jetifier

From official doc

When this flag is set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX dependencies by rewriting their binaries. The flag is false by default if it is not specified.

It is useful for compatibility. When a Consumer uses androidX and a Producer uses support. For example when your project on AndroidX wants to use a dependency which uses support library instead of AndroidX[Example]

Comments

5

Jetifier

The jetifier is a handy tool that automatically migrates your dependencies to AndroidX at build time. Without it, you'd need every dependency you use to have an AndroidX version before you can migrate, and that probably won't happen for some time.

There's an important limitation to note: the jetifier only works on packaged artifacts. It does not work on your source code, which you are expected to update yourself

for enabling AndroidX, you need to add 2 flags to your gradle.properties file. The first flag tells the Android Plugin to use AndroidX packages instead of AppCompat, and the second flag will enable the Jetifier :

android.useAndroidX=true android.enableJetifier=true 

See this, this post to understand more about AndroidX

Comments

-1

Jetifier is a tool that helps migrate third-party libraries from the Android Support Library to AndroidX. It:

  1. Converts Dependencies: Transforms support library dependencies to their AndroidX equivalents

  2. Handles Binary Compatibility: Ensures libraries work with AndroidX projects

  3. Automates Migration: Reduces manual work in the migration process

  4. Resolves Conflicts: Helps manage dependencies that haven't migrated to AndroidX yet

It's used for:

  • Enables automatic conversion of third-party libraries

  • Only needed if you use libraries that haven't migrated to AndroidX (from Android Support Library)

  • Can be disabled once all dependencies are migrated

I wrote quite a post on that topic... https://blog.ditectrev.com/blog/software-development/mobile-development/native/android/jetifier-androidx-migration-guide#jetifier-and-androidx-migration-a-complete-guide

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.