简短错误日志:
> :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()
MyApplication :
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$1$1$2.invoke(CompileServiceImpl.kt:441) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:101) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1020) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.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$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:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(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$2.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$2.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$1.invoke(KotlinToJVMBytecodeCompiler.kt:375) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.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
我已经阅读了所有相关问题,例如:
所有人都说支持库的版本不一样;否则compileSdkVersion
必须为 28 。
我已经考虑了所有这些,但是错误仍然存在!
我认为使用 androidx , kotlin 和 dagger 会出错/遗漏;但是我不确定是什么。
答案 0 :(得分:2)
首先,将databinding
设置为false,以查看是否存在任何资源/布局错误。 (在我的情况下,这是第一个错误。是的,还有其他错误,我不再将其粘贴到问题中了)。
在multiDexEnabled true
范围内的应用模块build.gradle
中设置defaultConfig
(或在data
和presentation
模块的{{1}中) }文件(如果您要像我一样遵循“干净的体系结构”)。
将以下摘要代码添加到build.gradle
和data
的{{1}}文件中:
presentation
不要忘记再次将build.gradle
设置为true。
android {
...
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
databinding
文件中:classpath 'com.android.tools.build:gradle:3.3.0-alpha11'
;当然,根据您的硬件配置。local.properties
。 (在org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m
文件内部)。将以下代码段代码添加到CustomMyApplication:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
将以下几行添加到您的gradle-wrapper.properties
文件中:
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 = '1.0.0-rc02'//'1.0.0-alpha1'
资料来源:
https://github.com/google/dagger/issues/1245
Androidx and databinding
https://stackoverflow.com/a/41100670/421467
https://stackoverflow.com/a/48531191/421467
https://stackoverflow.com/a/49525685/421467
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