Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable android.enableJetifier for specific module or depedency

Running Android Studio 3.2 with the following settings in my gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

I have a native project with some C/Java code. With these settings, the compilation fails with the following error message:

org.gradle.api.artifacts.transform.ArtifactTransformException: Failed to transform file 'android.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
java.lang.RuntimeException: Failed to transform 'C:\Android\sdk\platforms\android-28\android.jar' using Jetifier.

I believe it doesn't like my gradle file:

apply plugin: 'java'
...
dependencies {
   implementation files("${mySdkDir}/android.jar")
}

I know I can globally turn off enableJetifier which would indeed make this error go away. However, I only want to disable the jetifier for this specific module/dependency.

How do I set enableJetifier=false for a native/java module project?

like image 431
l33t Avatar asked Sep 24 '18 18:09

l33t


People also ask

Can I disable Jetifier?

You need to verify that your own code and all your dependencies (including transitives) are not support-library-dependent any more. it means that you achieved that. Now you can remove the android. enableJetifier flag from your gradle.

What is enable Jetifier?

android. enableJetifier=true. The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. Note: The built-in Android Studio migration might not handle everything.

Can I use library that used Android support with AndroidX projects?

Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components. You can continue to use the support library.


1 Answers

The question probably isn't how to disable the Jetifier for the module -

because this is coming from using the wrong plugin for the module.

apply plugin: "com.android.application"
// apply plugin: "com.android.library"

android {
    ...
}

There is no way to disable the Jetifier for a module, because it is a project-wide feature... and so the only way around this is not to have android.jar being explicitly listed in the dependencies block. It's not even meant to be packaged, therefore it has lost nothing in there - and it's not meant to be processed by the Jetifier, which merely is the result of having it declared as a dependency.

like image 68
Martin Zeitler Avatar answered Sep 30 '22 12:09

Martin Zeitler