14

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?

l33t
  • 18,692
  • 16
  • 103
  • 180

1 Answers1

1

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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • The fact that an external `.jar` (in this case the very `android.jar`) crashed the jetifier was confirmed as a bug by Google and subsequently fixed. You are correct that the jetifier cannot be disabled on module level. – l33t Jul 18 '19 at 15:30
  • @l33t it's absolutely pointless to use the Jetifier on the framework jar, because there won't be the expected `com.android.support` namespace to transform into `androidx`. Building Android applications with the Java plugin is the root cause; wouldn't consider it a bug, but rather an abusive utilization of the tools available. the only flaw here is, that it even tries to transform the framework jar. – Martin Zeitler Jul 18 '19 at 23:41
  • Usually, when a piece of software crashes you call it a bug. Being able to reproduce this crash using the framework jar is, well, an easy way to reproduce the crash (usually appreciated by developers). Building Android *libraries* as java plugins certainly is a less common thing to do, but it's perfectly valid. – l33t Jul 19 '19 at 13:13