11

Gone down the rabbit hole of migrating to AndroidX...

I've nearly completed the migration, but running into one error I can't seem to get past.

Already tried Clean & Rebuild and Invalidate Caches / Restart

It looks like something is injecting @Deprecated into the R.java file which is not recognized.

The app's build.gradle file is long but here's relevant parts (can post more if relevant):


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'

        ...
    }
}


I get a series of errors from the Kotlin compiler

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

which links to R.java

R.java file screenshot

I have not used titleMargins anywhere in my project. When I do a search, the @Deprecated values only show up in the Android sdk and com.google.android.material artifacts, contained in .gradle/caches/. I've tried deleting this folder and it shows up again with each compile.

I think it has something to do with databinding, but I've been at it for days and am unable to find a cause.

The source for that particular annotation processor file I found here: ProcessDataBinding.java

Update 1

This great article on The Reality of Migrating to AndroidX explains that Android X's jetifier tool does not handle generated code. I have seen other related SO posts dealing with issues with ButterKnife, Dagger, etc, but we're not using any of these. We are using several databinding and compiled libraries, but I'm not sure which one is the source of the bad references. So my question is how do I find the source of this generated code and fix it?

Update 2

Going back to the original pre-AndroidX project, this error actually occurs in upgrading the support library to 28. Just changing the line

implementation "com.android.support:appcompat-v7:27.1.1"

to

implementation "com.android.support:appcompat-v7:28.0.0"

will trigger the compilation error.

Following a trail of crumbs I came across this issue tracker: Databinding v2 produces errors when another annotation processor fails which may be related but I'm still not sure how to fix it.

Evelyn
  • 2,588
  • 3
  • 22
  • 47

1 Answers1

0

Change this:

compileOptions {
    dataBinding {
        enabled = true
    }
}

Into this:

dataBinding {
    enabled = true
}
compileOptions {

}

And for com.nextfaze.poweradapters you'd need to enable the Jetifier in gradle.properties:

android.useAndroidX=true
android.enableJetifier=true
Martin Zeitler
  • 1
  • 19
  • 155
  • 216