android.useAndroidX=true
,表示主工程使用AndroidX形式。
android.enableJetifier=true
,表示针对主工程中使用到的三方库,也会自动执行AndroidX的替换过程。
同时,在自动执行三方库的替换时,出下了如下报错信息:
ERROR: Unable to resolve dependency for ‘:MyCorn@prodDebug/compileClasspath’: Failed to transform file ‘fingerprint-1.1.1.aar’ to match attributes {artifactType=processed-aar} using transform JetifyTransform
大致的意思是使用JetifyTransform
对fingerprint-1.1.1.aar
进行替换过程中,出现了问题。但具体问题没有进一步的提示信息。于是,直接通过命令执行下构建看一下:
./gradlew assembleDevDebug
…
…
1: Task failed with an exception.
- What went wrong:
Could not resolve all files for configuration ‘:MyCorn:devDebugCompileClasspath’.
Failed to transform file ‘fingerprint-1.1.1.aar’ to match attributes {artifactType=processed-aar} using transform JetifyTransform
Failed to transform ‘/Users/corn/.gradle/caches/modules-2/files-2.1/com.corn.feature/fingerprint/1.1.1/ae2da4c824fb2923eac7a1340222d50d6308f7ea/fingerprint-1.1.1.aar’ using Jetifier. Reason: 8. (Run with --stacktrace for more details.) To disable Jetifier, set android.enableJetifier=false in your gradle.properties file.
进而,带上–stacktrace看看。
./gradlew assembleDevDebug --stacktrace
…
…
Caused by: java.lang.ArrayIndexOutOfBoundsException: 8
at org.objectweb.asm.ClassReader.readFrameType(ClassReader.java:2313)
at org.objectweb.asm.ClassReader.readFrame(ClassReader.java:2269)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1448)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
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:328)
at com.android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:41)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:316)
at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:66)
at com.android.tools.build.jetifier.proce 《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》无偿开源 徽信搜索公众号【编程进阶路】 ssor.Processor.visit(Processor.kt:316)
at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:66)
at com.android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:312)
at com.android.tools.build.jetifier.processor.Processor.transform(Processor.kt:175)
at com.android.build.gradle.internal.dependency.JetifyTransform.transform(JetifyTransform.kt:199)
… 39 more
我们发现,JetifyTransform内部使用了ASM,在对aar进行ClassReader的过程中抛出了异常。并且从错误栈信息上看,应该有一类叫jetifier
的工具,是在这个工具中调用的ASM操作。
官方文档搜索下,果然发现了jetifier
的踪迹。
[developer.android.com/studio/comm…](()
同样的,Google Source上也找到了其对应的实现。
[android.googlesource.com/platform/fr…](()
下载对应的jetifier-standalone
,解压后,执行命令对fingerprint-1.1.1.aar
执行AndroidX转化。
➜ bin ./jetifier-standalone -i ./fingerprint-1.1.1.aar -o 11.aar
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 8
at org.objectweb.asm.ClassReader.readFrameType(ClassReader.java:2313)
at org.objectweb.asm.ClassReader.readFrame(ClassReader.java:2269)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1448)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.android.tools.build.jetifier.processor.transform.bytecode.ByteCodeTransformer.runTransform(ByteCodeTransformer.kt:40)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:539)
at com.android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:53)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:521)
at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:76)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:521)
at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:76)
at com.android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:517)
at com.android.tools.build.jetifier.processor.Processor.transform2(Processor.kt:291)
at com.android.tools.build.jetifier.processor.Processor.transform2 d e f a u l t ( P r o c e s s o r . k t : 251 ) a t c o m . a n d r o i d . t o o l s . b u i l d . j e t i f i e r . s t a n d a l o n e . M a i n . r u n ( M a i n . k t : 156 ) a t c o m . a n d r o i d . t o o l s . b u i l d . j e t i f i e r . s t a n d a l o n e . M a i n default(Processor.kt:251) at com.android.tools.build.jetifier.standalone.Main.run(Main.kt:156) at com.android.tools.build.jetifier.standalone.Main default(Processor.kt:251)atcom.android.tools.build.jetifier.standalone.