无法访问 ActivityCompatApi23 - Kotlin - AndroidX - Dagger 2.17
Cannot access ActivityCompatApi23 - Kotlin - AndroidX - Dagger 2.17
简短错误日志:
> :presentation:transformDataBindingWithDataBindingMergeArtifactsForDebug
> e: E:\MVVM\presentation\build\tmp\kapt3\stubs\debug\com\example\mvvm\ui\base\BaseActivity.java:9: error: cannot access ActivityCompatApi23
public abstract class BaseActivity extends dagger.android.support.DaggerAppCompatActivity {
^
class file for android.support.v4.app.ActivityCompatApi23 not found
e: java.lang.IllegalStateException: failed to analyze: java.lang.AssertionError: annotation tree hasn't been attributed yet: @kotlin.Metadata(mv = {1, 1, 11}, bv = {1, 0, 2}, k = 1, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b&\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002\u00a8\u0006\u0003"}, d2 = {"Lcom/example/mvvm/ui/base/BaseActivity;", "Ldagger/android/support/DaggerAppCompatActivity;", "()V", "presentation_debug"})
图书馆版本:
ext{
minSdkVersion = 14
targetSdkVersion = 28
androidCompileSdkVersion = 28
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
androidPluginVersion = '3.1.4'
kotlinVersion = '1.2.70'
supportVersion = '1.0.0-alpha1'
daggerVersion = '2.17'
roomVersion = '2.0.0-beta01'
lifecycleVersion = '2.0.0-beta01'
rxJavaVersion = '2.2.2'
rxAndroidVersion = '2.1.0'
supportTest = '1.1.0-alpha1'
multidexVersion = '2.0.0'
...
}
kotlin: "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}",
rxJava: "io.reactivex.rxjava2:rxjava:${rxJavaVersion}",
rxAndroid: "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion",
appCompat: "androidx.appcompat:appcompat:$supportVersion",
material: "com.google.android.material:material:$supportVersion",
supportv4: "androidx.legacy:legacy-support-v4:$supportVersion",
appcompatv7: "androidx.appcompat:appcompat:$supportVersion",
recyclerview: "androidx.recyclerview:recyclerview:$supportVersion",
cardview: "androidx.cardview:cardview:$supportVersion",
annotation: "androidx.annotation:annotation:$supportVersion",
javaxInject: "javax.inject:javax.inject:$javaxInjectVersion",
dagger: "com.google.dagger:dagger:${daggerVersion}",
daggerAndroid: "com.google.dagger:dagger-android:${daggerVersion}",
daggerAndroidSupport: "com.google.dagger:dagger-android-support:${daggerVersion}",
daggerAndroidProcessor: "com.google.dagger:dagger-android- processor:${daggerVersion}",
daggerCompiler: "com.google.dagger:dagger-compiler:${daggerVersion}",
room: "androidx.room:room-runtime:$roomVersion",
roomCompiler: "androidx.room:room-compiler:$roomVersion",
roomCommon: "androidx.room:room-common:$roomVersion",
constraintLayout: "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion",
multidex: "androidx.multidex:multidex:$multidexVersion",
lifecycleExtensions: "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion",
lifecycleCommon: "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
...
Android Studio 版本: 3.1.4
BaseActivity:
abstract class BaseActivity : DaggerAppCompatActivity()
我的应用程序:
class MyApplication : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerAppComponent.builder().create(this)
}
}
AppComponent:
@Singleton
@Component(modules = [
AndroidSupportInjectionModule::class,
ViewModelBuilder::class,
AppModule::class,
BaseModule::class
])
interface AppComponent : AndroidInjector<MyApplication> {
@Component.Builder
abstract class Builder : AndroidInjector.Builder<MyApplication>()
}
AppModule:
@Module(includes = [NetModule::class, DbModule::class])
abstract class AppModule {
@ApplicationContext
@Binds
abstract fun provideApplicationContext(myApplication: MyApplication): Context
}
完整错误日志:
:presentation:transformDataBindingWithDataBindingMergeArtifactsForDebug
> e: E:\MVVM\presentation\build\tmp\kapt3\stubs\debug\com\example\mvvm\ui\base\BaseActivity.java:9: error: cannot access ActivityCompatApi23
public abstract class BaseActivity extends dagger.android.support.DaggerAppCompatActivity {
^
class file for android.support.v4.app.ActivityCompatApi23 not found
e: java.lang.IllegalStateException: failed to analyze: java.lang.AssertionError: annotation tree hasn't been attributed yet: @kotlin.Metadata(mv = {1, 1, 11}, bv = {1, 0, 2}, k = 1, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b&\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002\u00a8\u0006\u0003"}, d2 = {"Lcom/example/mvvm/ui/base/BaseActivity;", "Ldagger/android/support/DaggerAppCompatActivity;", "()V", "presentation_debug"})
at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:125)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile.invoke(CompileServiceImpl.kt:441)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile.invoke(CompileServiceImpl.kt:101)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:1020)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:101)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1062)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1019)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:440)
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:346)
at sun.rmi.transport.Transport.run(Transport.java:200)
at sun.rmi.transport.Transport.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:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run[=17=](TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.AssertionError: annotation tree hasn't been attributed yet: @kotlin.Metadata(mv = {1, 1, 11}, bv = {1, 0, 2}, k = 1, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b&\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002\u00a8\u0006\u0003"}, d2 = {"Lcom/example/mvvm/ui/base/BaseActivity;", "Ldagger/android/support/DaggerAppCompatActivity;", "()V", "presentation_debug"})
at com.sun.tools.javac.util.Assert.error(Assert.java:133)
at com.sun.tools.javac.util.Assert.checkNonNull(Assert.java:118)
at com.sun.tools.javac.comp.Check.validateTypeAnnotation(Check.java:2745)
at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitAnnotation(Attr.java:4484)
at com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:2317)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
at com.sun.tools.javac.tree.TreeScanner.visitModifiers(TreeScanner.java:315)
at com.sun.tools.javac.tree.JCTree$JCModifiers.accept(JCTree.java:2343)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitClassDef(Attr.java:4566)
at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
at com.sun.tools.javac.comp.Attr.validateTypeAnnotations(Attr.java:4473)
at com.sun.tools.javac.code.TypeAnnotations.run(TypeAnnotations.java:142)
at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:155)
at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:129)
at com.sun.tools.javac.comp.Enter.complete(Enter.java:512)
at com.sun.tools.javac.comp.Enter.main(Enter.java:471)
at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:47)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:27)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:213)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:178)
at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:96)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration.invoke(TopDownAnalyzerFacadeForJVM.kt:95)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:105)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze.invoke(KotlinToJVMBytecodeCompiler.kt:375)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze.invoke(KotlinToJVMBytecodeCompiler.kt:67)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:366)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:120)
... 30 more
> :presentation:kaptDebugKotlin FAILED
> FAILURE: Build failed with an exception.
> * What went wrong:
Execution failed for task ':presentation:kaptDebugKotlin'.
> Internal compiler error. See log for more details
我已经阅读了所有相关问题,例如:
- cannot access ActivityCompatApi23 class file
- ...
都说支持库的版本不一样;或者 compileSdkVersion
必须是 28。
我已经考虑了所有这些,但错误仍然存在!
我认为 wrong/missed 使用 androidx、kotlin 和 dagger;但我不确定它是什么。
首先把databinding
设置为false,看看有没有resources/layout错误。 (就我而言,这是第一个错误。是的,出现了其他错误,我不再将其粘贴到问题中)。
在应用程序模块的 build.gradle
中设置 multiDexEnabled true
,在 defaultConfig
范围内(或在 data
和 presentation
模块中build.gradle
个文件,如果你像我一样遵循一个干净的架构)。
将以下代码段添加到 data
和 presentation
的 build.gradle
文件中:
android {
...
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
不要忘记再次将 databinding
设置为 true。
- 将构建 Gradle 工具版本更改为
classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
- 将此行添加到您的
local.properties
文件中:org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m
;当然,根据你的硬件配置。
- 使用Gradle 4.4 以上的分发版本。喜欢:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
。 (在 gradle-wrapper.properties
文件内)。
将以下代码片段添加到您的 CustomMyApplication:
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(this)
}
将以下行添加到您的 gradle.properties
文件中:
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
- 将 supportVersion 键更改为
supportVersion = '1.0.0-rc02'//'1.0.0-alpha1'
- 将 daggerVersion 密钥更改为
daggerVersion = '2.16'//2.17
- 将 roomVersion 密钥更改为
roomVersion = '2.0.0-alpha1'//'2.0.0-beta01'
来源:
https://github.com/google/dagger/issues/1245
https://developer.android.com/studio/build/multidex
https://developer.android.com/topic/libraries/support-library/refactor
https://developer.android.com/topic/libraries/architecture/adding-components
https://developer.android.com/jetpack/docs/release-notes#july_2_2018
https://github.com/JakeWharton/butterknife/issues/1270#issuecomment-388449463
简短错误日志:
> :presentation:transformDataBindingWithDataBindingMergeArtifactsForDebug
> e: E:\MVVM\presentation\build\tmp\kapt3\stubs\debug\com\example\mvvm\ui\base\BaseActivity.java:9: error: cannot access ActivityCompatApi23
public abstract class BaseActivity extends dagger.android.support.DaggerAppCompatActivity {
^
class file for android.support.v4.app.ActivityCompatApi23 not found
e: java.lang.IllegalStateException: failed to analyze: java.lang.AssertionError: annotation tree hasn't been attributed yet: @kotlin.Metadata(mv = {1, 1, 11}, bv = {1, 0, 2}, k = 1, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b&\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002\u00a8\u0006\u0003"}, d2 = {"Lcom/example/mvvm/ui/base/BaseActivity;", "Ldagger/android/support/DaggerAppCompatActivity;", "()V", "presentation_debug"})
图书馆版本:
ext{
minSdkVersion = 14
targetSdkVersion = 28
androidCompileSdkVersion = 28
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
androidPluginVersion = '3.1.4'
kotlinVersion = '1.2.70'
supportVersion = '1.0.0-alpha1'
daggerVersion = '2.17'
roomVersion = '2.0.0-beta01'
lifecycleVersion = '2.0.0-beta01'
rxJavaVersion = '2.2.2'
rxAndroidVersion = '2.1.0'
supportTest = '1.1.0-alpha1'
multidexVersion = '2.0.0'
...
}
kotlin: "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}",
rxJava: "io.reactivex.rxjava2:rxjava:${rxJavaVersion}",
rxAndroid: "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion",
appCompat: "androidx.appcompat:appcompat:$supportVersion",
material: "com.google.android.material:material:$supportVersion",
supportv4: "androidx.legacy:legacy-support-v4:$supportVersion",
appcompatv7: "androidx.appcompat:appcompat:$supportVersion",
recyclerview: "androidx.recyclerview:recyclerview:$supportVersion",
cardview: "androidx.cardview:cardview:$supportVersion",
annotation: "androidx.annotation:annotation:$supportVersion",
javaxInject: "javax.inject:javax.inject:$javaxInjectVersion",
dagger: "com.google.dagger:dagger:${daggerVersion}",
daggerAndroid: "com.google.dagger:dagger-android:${daggerVersion}",
daggerAndroidSupport: "com.google.dagger:dagger-android-support:${daggerVersion}",
daggerAndroidProcessor: "com.google.dagger:dagger-android- processor:${daggerVersion}",
daggerCompiler: "com.google.dagger:dagger-compiler:${daggerVersion}",
room: "androidx.room:room-runtime:$roomVersion",
roomCompiler: "androidx.room:room-compiler:$roomVersion",
roomCommon: "androidx.room:room-common:$roomVersion",
constraintLayout: "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion",
multidex: "androidx.multidex:multidex:$multidexVersion",
lifecycleExtensions: "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion",
lifecycleCommon: "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
...
Android Studio 版本: 3.1.4
BaseActivity:
abstract class BaseActivity : DaggerAppCompatActivity()
我的应用程序:
class MyApplication : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerAppComponent.builder().create(this)
}
}
AppComponent:
@Singleton
@Component(modules = [
AndroidSupportInjectionModule::class,
ViewModelBuilder::class,
AppModule::class,
BaseModule::class
])
interface AppComponent : AndroidInjector<MyApplication> {
@Component.Builder
abstract class Builder : AndroidInjector.Builder<MyApplication>()
}
AppModule:
@Module(includes = [NetModule::class, DbModule::class])
abstract class AppModule {
@ApplicationContext
@Binds
abstract fun provideApplicationContext(myApplication: MyApplication): Context
}
完整错误日志:
:presentation:transformDataBindingWithDataBindingMergeArtifactsForDebug > e: E:\MVVM\presentation\build\tmp\kapt3\stubs\debug\com\example\mvvm\ui\base\BaseActivity.java:9: error: cannot access ActivityCompatApi23 public abstract class BaseActivity extends dagger.android.support.DaggerAppCompatActivity { ^ class file for android.support.v4.app.ActivityCompatApi23 not found e: java.lang.IllegalStateException: failed to analyze: java.lang.AssertionError: annotation tree hasn't been attributed yet: @kotlin.Metadata(mv = {1, 1, 11}, bv = {1, 0, 2}, k = 1, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b&\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002\u00a8\u0006\u0003"}, d2 = {"Lcom/example/mvvm/ui/base/BaseActivity;", "Ldagger/android/support/DaggerAppCompatActivity;", "()V", "presentation_debug"}) at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:125) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile.invoke(CompileServiceImpl.kt:441) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile.invoke(CompileServiceImpl.kt:101) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:1020) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda.invoke(CompileServiceImpl.kt:101) at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137) at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1062) at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1019) at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:440) 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:346) at sun.rmi.transport.Transport.run(Transport.java:200) at sun.rmi.transport.Transport.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:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run[=17=](TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.AssertionError: annotation tree hasn't been attributed yet: @kotlin.Metadata(mv = {1, 1, 11}, bv = {1, 0, 2}, k = 1, d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b&\u0018\u00002\u00020\u0001B\u0005\u00a2\u0006\u0002\u0010\u0002\u00a8\u0006\u0003"}, d2 = {"Lcom/example/mvvm/ui/base/BaseActivity;", "Ldagger/android/support/DaggerAppCompatActivity;", "()V", "presentation_debug"}) at com.sun.tools.javac.util.Assert.error(Assert.java:133) at com.sun.tools.javac.util.Assert.checkNonNull(Assert.java:118) at com.sun.tools.javac.comp.Check.validateTypeAnnotation(Check.java:2745) at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitAnnotation(Attr.java:4484) at com.sun.tools.javac.tree.JCTree$JCAnnotation.accept(JCTree.java:2317) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57) at com.sun.tools.javac.tree.TreeScanner.visitModifiers(TreeScanner.java:315) at com.sun.tools.javac.tree.JCTree$JCModifiers.accept(JCTree.java:2343) at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49) at com.sun.tools.javac.comp.Attr$TypeAnnotationsValidator.visitClassDef(Attr.java:4566) at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693) at com.sun.tools.javac.comp.Attr.validateTypeAnnotations(Attr.java:4473) at com.sun.tools.javac.code.TypeAnnotations.run(TypeAnnotations.java:142) at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:155) at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:129) at com.sun.tools.javac.comp.Enter.complete(Enter.java:512) at com.sun.tools.javac.comp.Enter.main(Enter.java:471) at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:982) at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:47) at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:27) at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:213) at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:178) at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:96) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration.invoke(TopDownAnalyzerFacadeForJVM.kt:95) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:105) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze.invoke(KotlinToJVMBytecodeCompiler.kt:375) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze.invoke(KotlinToJVMBytecodeCompiler.kt:67) at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:366) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:120) ... 30 more > :presentation:kaptDebugKotlin FAILED > FAILURE: Build failed with an exception. > * What went wrong: Execution failed for task ':presentation:kaptDebugKotlin'. > Internal compiler error. See log for more details
我已经阅读了所有相关问题,例如:
- cannot access ActivityCompatApi23 class file
- ...
都说支持库的版本不一样;或者 compileSdkVersion
必须是 28。
我已经考虑了所有这些,但错误仍然存在!
我认为 wrong/missed 使用 androidx、kotlin 和 dagger;但我不确定它是什么。
首先把
databinding
设置为false,看看有没有resources/layout错误。 (就我而言,这是第一个错误。是的,出现了其他错误,我不再将其粘贴到问题中)。在应用程序模块的
build.gradle
中设置multiDexEnabled true
,在defaultConfig
范围内(或在data
和presentation
模块中build.gradle
个文件,如果你像我一样遵循一个干净的架构)。将以下代码段添加到
data
和presentation
的build.gradle
文件中:android { ... compileOptions { targetCompatibility 1.8 sourceCompatibility 1.8 }
不要忘记再次将
databinding
设置为 true。- 将构建 Gradle 工具版本更改为
classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
- 将此行添加到您的
local.properties
文件中:org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m
;当然,根据你的硬件配置。 - 使用Gradle 4.4 以上的分发版本。喜欢:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
。 (在gradle-wrapper.properties
文件内)。 将以下代码片段添加到您的 CustomMyApplication:
override fun attachBaseContext(base: Context) { super.attachBaseContext(base) MultiDex.install(this) }
将以下行添加到您的
gradle.properties
文件中:android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true
- 将 supportVersion 键更改为
supportVersion = '1.0.0-rc02'//'1.0.0-alpha1'
- 将 daggerVersion 密钥更改为
daggerVersion = '2.16'//2.17
- 将 roomVersion 密钥更改为
roomVersion = '2.0.0-alpha1'//'2.0.0-beta01'
来源:
https://github.com/google/dagger/issues/1245
https://developer.android.com/studio/build/multidex
https://developer.android.com/topic/libraries/support-library/refactor
https://developer.android.com/topic/libraries/architecture/adding-components
https://developer.android.com/jetpack/docs/release-notes#july_2_2018
https://github.com/JakeWharton/butterknife/issues/1270#issuecomment-388449463