OkBuck不适用于零依赖的Android Jetifier

时间:2019-01-24 11:18:30

标签: android android-jetifier okbuck

我试图在Android Studio 3.3中使用okbuck,但是我陷入了AndroidX的困境。当我将所有依赖项转换为androidx并设置时:

android.enableJetifier=true
android.useAndroidX=true

运行时出现以下错误:

./buckw install --run //app:bin_debug
Exception in thread "main" java.lang.IllegalArgumentException: The given artifact contains a string literal with a package reference 'android.support.design.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx. 
at com.android.tools.build.jetifier.processor.transform.bytecode.CoreRemapperImpl.rewriteString(CoreRemapperImpl.kt:91)
        at com.android.tools.build.jetifier.processor.transform.bytecode.asm.CustomRemapper.mapValue(CustomRemapper.kt:75)
        at org.objectweb.asm.commons.ClassRemapper.visitField(ClassRemapper.java:113)
        at org.objectweb.asm.ClassReader.readField(ClassReader.java:883)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:694)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
        at com.android.tools.build.jetifier.processor.transform.bytecode.ByteCodeTransformer.runTransform(ByteCodeTransformer.kt:39)
        at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:366)
        at com.android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:41)
        at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:348)
        at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:70)
        at com.android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:344)
        at com.android.tools.build.jetifier.processor.Processor.transform(Processor.kt:207)
        at com.android.tools.build.jetifier.processor.Processor.transform$default(Processor.kt:194)
        at com.android.tools.build.jetifier.standalone.Main.run(Main.kt:147)
        at com.android.tools.build.jetifier.standalone.Main$Companion.main(Main.kt:101)
        at com.android.tools.build.jetifier.standalone.Main.main(Main.kt)

我什至可以注释掉所有依赖项,删除-重新初始化okbuck(这样就不用缓存了),并且当jetifier仍然打开时,错误不断弹出。

我使用的是okbuck 0.46.2版本,据说Jetifier从0.44.1开始工作。

1 个答案:

答案 0 :(得分:0)

在我从事okbuck示例项目时,遇到了与您类似的问题。我已经通过在根级别build.gradle中添加jetifier块解决了此问题。请参阅已修复AndroidX问题的拉取请求here

这是与okbuck相关的整个代码块。

okbuck {

    buildToolVersion = '28.0.3'

    lint {
       disabled = true
    }
    externalDependencies {
        downloadInBuck = false
    }
    jetifier {
        aarOnly = true
    }
}