4

The Jetifier tool is used as part of the AndroidX migration tool bundled with Android Studio. There is an issue with the tool, however, that is outlined here: https://issuetracker.google.com/issues/113224601.

The error message looks like this when running the Jetifier on certain libraries (one particular library keeps popping up for multiple users: org.eclipse.jdt.core):

Failed to transform '/path/to/library/org.eclipse.jdt.core-3.10.0.jar' using Jetifier.
Reason: The type does not support '.' as package separator!

This issue has been fixed for a while in the Jetifier tool itself, but the fixed version has not been included in any Android Studio updates yet (even the latest canary build).

I can confirm that running the standalone Jetifier works in transforming the problematic libraries, but I have no idea how to get these transformed libraries into our project. Off the top of my head, I can think of two different ways to get this migration to AndroidX to work:

  1. Run the standalone tool on each library and instruct Gradle to use those versions (I might need to tell the Gradle tasks not to run the Jetifier on them)

  2. Instruct the Gradle tasks to use the standalone tool in place of the one shipped with Android Studio.

Any help getting either of the above suggested fixes to work would be greatly appreciated (or if there is another way, I'd love to know about it). The internals of the Android Gradle build system are incredibly complicated, and I really need some gurus' assistance to get past this roadblock.

This is a serious road block for us since we want to begin the process of migrating our app in parallel with our development. There are a lot of things we need to iron out with this migration, and being ready to "flip the switch" when the tool is finally updated would help keep our releases on track.

Thanks!

nkotula
  • 71
  • 1
  • 1
  • 6
  • Hi nkotula, I'm sure every issue is different, but I found that I had tons of issues in the migration in Android Studio 3.1 when I did it all manually. So I eventually reverted my changes, and opened in 3.2 Android Studio which has the migration tool built in. This tool got me like 95% of the way there. A few tweaks and changes and I was building fine. It even generates the gradle.properties which includes the useJetifier. I have many dependencies and didn't have any issues with Jetifier. So hopefully it's something in the migration and not the tool, but can't say that for sure. – Sam Nov 01 '18 at 13:13
  • worst case scenario as a temporary fix if it truly is a namespace problem, is you could actually get the source for that library and include it as a submodule until the problem is resolved later. – Sam Nov 01 '18 at 13:15

2 Answers2

3

Actually, from that same thread that I linked, there's a workaround:

Sorry jetifier beta01 was not binary compatible with alpha10.

Please try:

buildscript {
    dependencies {
        classpath 'com.android.tools.build.jetifier:jetifier-processor:1.0.0-beta02'
    }
}

So, I guess now you can specify the newest version of the Jetifier in your buildscript.

I really should have scrolled all the way to the bottom of that thread before posting this, but now hopefully this workaround is more visible to people.

UPDATE

It seems this workaround does not work with DataBinding enabled. It looks like the new Jetifier tool is trying to run on the old version:

Failed to transform '/path/to/library/jetifier-core-1.0.0-alpha10.jar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android/support/v4' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.

UPDATE 2 (20 Nov 2018):

There is a workaround to the issue of Jetifier trying to Jetify itself being released in AGP 3.3.0-rc01 and 3.4.0-alpha04. The devs are adding the ability to blacklist libraries from being Jetified. In your gradle.properties file, add a comma-separated list of Regular Expressions to match what files you don't want the Jetifier to touch. For example:

android.jetifier.blacklist = doNot.*\\.jar

Would exclude /path/to/doNotJetify.jar

nkotula
  • 71
  • 1
  • 1
  • 6
  • I ran into the same thing. Did you find any solution? – mgR Nov 08 '18 at 06:04
  • 1
    There's a new issue tracked to solve the DataBinding issue: [https://issuetracker.google.com/issues/119135578](https://issuetracker.google.com/issues/119135578). Apparently the original issue is fixed in AGP 3.3.0-beta3 ([noted here](https://issuetracker.google.com/issues/113224601#comment15)), but sadly this fix doesn't help the DataBinding issue, so I'm still stuck. – nkotula Nov 08 '18 at 16:48
  • For some reasons, local builds works good (ubuntu), but builds in docker image (bitbucket pipelines + ubuntu) were failing due to JetifyTransform issue on some libs. android.jetifier.blacklist helped to exclude these libs. – demaksee Jan 29 '19 at 11:59
0

I´m a bite late to the party, but I think there is only one fast option to solve that issue:

Go to Google Archives, Agree save and terms and download Android Studio 3.3 Beta 2 - this is the latest version before the problem occurs. You also have to downgrade your build.gradle to

classpath 'com.android.tools.build:gradle:3.3.0-beta02'

using gradle-4.10.2-all should be no problem.

Perhaps the problem will be fixed with the next beta or canary release, but for now this was the only option that worked out for me.

Dennis Allert
  • 580
  • 1
  • 9
  • 8