Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Jetifier?

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

like image 753
Ksenia Avatar asked Aug 03 '18 22:08

Ksenia


People also ask

What is Jetifier for?

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.

Should I disable Jetifier?

So, disabling jetifier is a good idea for your android project if you want to reduce the build speed. But doing that is not always a trivial task. That's why we prepared a list of 6 steps to follow, so you can fully migrate your app to AndroidX and then safely disable Jetifier .

Is Jetifier deprecated?

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 (got deprecated after 28.0. 0 version) and AndroidX package, which is redundant.


2 Answers

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 (got 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 moved now to androidx package, so how will PhotoView get androidx AppCompatImageView? And app still runs in device.

Who made this run ?

Jetifier, which converts all support package of dependency at build time.

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

Conclusion

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

See this post to understand more about AndroidX.

Info

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

image2

image1

like image 137
Khemraj Sharma Avatar answered Oct 19 '22 07:10

Khemraj Sharma


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

like image 26
silwar Avatar answered Oct 19 '22 06:10

silwar