不再是迁移到AndroidX的烦恼...
我几乎完成了迁移,但是遇到了一个似乎无法逾越的错误。
已经尝试Clean & Rebuild
和Invalidate Caches / Restart
似乎是将@Deprecated注入到无法识别的R.java文件中。
该应用程序的build.gradle
文件很长,但是这里有相关部分(如果相关,可以发布更多内容):
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 17
targetSdkVersion 29
}
compileOptions {
dataBinding {
enabled = true
}
}
dependencies {
...
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.0-alpha01'
def rxlifecycleVersion = "3.1.0"
implementation "io.reactivex.rxjava3:rxjava:3.0.0-RC4"
implementation "com.trello.rxlifecycle3:rxlifecycle:$rxlifecycleVersion"
implementation "com.trello.rxlifecycle3:rxlifecycle-kotlin:$rxlifecycleVersion"
implementation "com.trello.rxlifecycle3:rxlifecycle-android:$rxlifecycleVersion"
implementation "com.trello.rxlifecycle3:rxlifecycle-components:$rxlifecycleVersion"
implementation(name: 'SectionCursorAdapter-3.0.0', ext: 'aar')
implementation 'com.nextfaze.poweradapters:power-adapters:0.24.1'
implementation 'com.nextfaze.poweradapters:power-adapters-data:0.24.1'
implementation 'com.nextfaze.poweradapters:power-adapters-recyclerview-v7:0.24.1'
implementation 'com.nextfaze.poweradapters:power-adapters-support-v4:0.24.1'
...
}
}
我从Kotlin编译器中得到了一系列错误
e: /.../R.java:6187: error: incompatible types: Deprecated cannot be converted to Annotation
@Deprecated
^
e: /.../R.java:28468: error: incompatible types: Deprecated cannot be converted to Annotation
@Deprecated
^
e: /.../R.java:28882: error: incompatible types: Deprecated cannot be converted to Annotation
@Deprecated
^
e: java.lang.IllegalStateException: failed to analyze: java.lang.NullPointerException
at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:182)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:164)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:54)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1558)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at android.databinding.annotationprocessor.ProcessDataBinding.getSupportedOptions(ProcessDataBinding.java:219)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.getSupportedOptions(incrementalProcessors.kt)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.createDependencyCollector(incrementalProcessors.kt:44)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.access$createDependencyCollector(incrementalProcessors.kt:22)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor$dependencyCollector$1.invoke(incrementalProcessors.kt:24)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor$dependencyCollector$1.invoke(incrementalProcessors.kt:22)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.getRuntimeType(incrementalProcessors.kt:69)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalAptCache.updateCache(IncrementalAptCache.kt:26)
at org.jetbrains.kotlin.kapt3.base.incremental.JavaClassCacheManager.updateCache(cache.kt:22)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:87)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:35)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:230)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:188)
at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:99)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:96)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:106)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:81)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:555)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:82)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:546)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:177)
... 23 more
链接到R.java
我没有titleMargins
在项目的任何地方使用过。当我进行搜索时,这些@Deprecated
值仅显示在Android sdk和com.google.android.material
包含在中的工件中.gradle/caches/
。我尝试删除此文件夹,并且每次编译时它再次出现。
我认为这与数据绑定有关,但是我已经花了好几天了,却找不到原因。
我在这里找到该特定注释处理器文件的源:ProcessDataBinding.java
更新1
这篇有关迁移到AndroidX的现实的出色文章解释说,Android X的jetifier工具无法处理生成的代码。我所看到的处理与问题等相关SO职位ButterKnife
,Dagger
等等,但我们不使用任何这些。我们正在使用几个数据绑定和编译库,但是我不确定哪个是错误引用的来源。所以我的问题是如何找到此生成代码的源并进行修复?
更新2
回到原始的AndroidX之前的项目,此错误实际上是在将支持库升级到28时发生的。
implementation "com.android.support:appcompat-v7:27.1.1"
至
implementation "com.android.support:appcompat-v7:28.0.0"
将触发编译错误。
经过一堆碎屑之后,我遇到了一个问题跟踪器:当另一个注释处理器出现故障时,数据绑定v2会产生错误,但可能仍与此有关,但我仍不确定如何解决。
Deprecated
R.java中是否有导入声明?