如何使用独立的Jetifier迁移到AndroidX? [英] How do I use the standalone Jetifier to migrate to AndroidX?

查看:1179
本文介绍了如何使用独立的Jetifier迁移到AndroidX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jetifier 工具用作捆绑的AndroidX迁移工具的一部分使用Android Studio.但是,该工具存在一个问题,概述如下: https://issuetracker.google.com/issues/113224601 .

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.

在某些库上运行Jetifier时,错误消息如下所示(一个特定的库不断弹出供多个用户使用:org.eclipse.jdt.core):

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!

这个问题已经在Jetifier工具本身中修复了一段时间,但是修复的版本尚未包含在任何Android Studio更新中(甚至是最新的canary版本).

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).

我可以确认运行独立的Jetifier可以转换有问题的库,但是我不知道如何将这些转换后的库添加到我们的项目中.我不由自主地想到了两种不同的方法来实现向AndroidX的迁移:

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. 在每个库上运行独立工具,并指示Gradle使用这些版本(我可能需要告诉Gradle任务 not 在它们上运行Jetifier)

  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)

指示Gradle任务使用独立工具代替 Android Studio附带的工具.

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

任何获得上述建议的修复工作的帮助将不胜感激(或者,如果有其他方法,我很想知道). Android Gradle构建系统的内部异常复杂,我真的需要一些专家的帮助才能克服这一障碍.

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.

谢谢!

推荐答案

实际上,在我链接的同一线程中,有一个解决方法:

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

抱歉,喷射器beta01与alpha10不二进制兼容.

Sorry jetifier beta01 was not binary compatible with alpha10.

请尝试:

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

所以,我想现在您可以在构建脚本中指定Jetifier的最新版本.

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.

更新

在启用DataBinding的情况下,此解决方法似乎不起作用.看来新的Jetifier工具正在尝试在旧版本上运行:

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:

无法转换'/path/to/library/jetifier-core-1.0.0-alpha10.jar' 使用Jetifier.原因:给定的工件包含字符串文字 带有不能安全地使用的包引用"android/support/v4" 改写.使用反射的库,例如注释处理器 需要手动更新以添加对androidx的支持.

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.

更新2(2018年11月20日):

UPDATE 2 (20 Nov 2018):

有一个针对Jetifier的问题的解决方法,该问题试图在AGP 3.3中发布. 0-rc01和3.4.0-alpha04 .开发人员增加了将JetJet列入黑名单的功能.在您的gradle.properties文件中,添加一个用逗号分隔的正则表达式列表,以匹配您不想让Jetifier触摸的文件.例如:

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

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

将排除/path/to/doNotJetify.jar

这篇关于如何使用独立的Jetifier迁移到AndroidX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆