Android Dagger 2使用Kotlin,奇怪的错误

时间:2018-03-11 10:59:41

标签: android kotlin dagger-2 dagger

我再次尝试了我之前发布的帖子,将Kotlin用于整个项目。

使用gradle构建时我没有错误,但是当我尝试编译项目时,我得到了。我试图在网上搜索一些答案,但无法找到任何东西。任何人都知道它可能是什么?

> e: [kapt] An exception occurred: java.lang.NoClassDefFoundError:
> com/google/auto/common/MoreTypes  at
> dagger.model.Key$Builder.type(Key.java:111)   at
> dagger.model.Key.builder(Key.java:102)    at
> dagger.internal.codegen.KeyFactory.forInjectConstructorWithResolvedType(KeyFactory.java:253)
>   at
> dagger.internal.codegen.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:266)
>   at
> dagger.internal.codegen.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:257)
>   at
> dagger.internal.codegen.InjectProcessingStep$1.visitVariableAsField(InjectProcessingStep.java:69)
>   at
> dagger.internal.codegen.InjectProcessingStep$1.visitVariableAsField(InjectProcessingStep.java:59)
>   at
> javax.lang.model.util.ElementKindVisitor6.visitVariable(ElementKindVisitor6.java:229)
>   at com.sun.tools.javac.code.Symbol$VarSymbol.accept(Symbol.java:1237)
>   at
> dagger.internal.codegen.InjectProcessingStep.process(InjectProcessingStep.java:58)
>   at
> dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:330)
>   at
> dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:181)
>   at
> org.jetbrains.kotlin.kapt3.ProcessorWrapper.process(annotationProcessing.kt:133)
>   at
> com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
>   at
> com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
>   at
> com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
>   at
> com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
>   at
> com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
>   at
> com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
>   at
> com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
>   at
> org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:89)
>   at
> org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:46)
>   at
> org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:226)
>   at
> org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:181)
>   at
> org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:93)   at
> org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:97)
>   at
> org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:107)
>   at
> org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:84)
>   at
> org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:374)
>   at
> org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:64)
>   at
> org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:101)
>   at
> org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:365)
>   at
> org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:130)
>   at
> org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161)
>   at
> org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:63)
>   at
> org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:108)
>   at
> org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
>   at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)  at
> org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:395)
>   at
> org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:97)
>   at
> org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:909)
>   at
> org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:97)
>   at
> org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
>   at
> org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:939)
>   at
> org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:908)
>   at
> org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:394)
>   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.ClassNotFoundException: com.google.auto.common.MoreTypes    at
> java.net.URLClassLoader.findClass(URLClassLoader.java:381)    at
> java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at
> java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 63 mor

ë

Gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

 android {
compileSdkVersion 26
  defaultConfig {
    applicationId "com.example.gebruiker.beertime1"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
   "android.support.test.runner.AndroidJUnitRunner"
     }
    buildTypes {
       release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}


     }

   dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

implementation 'com.google.dagger:dagger-android:2.14'
kapt 'com.google.dagger:dagger-android-processor:2.14'



implementation 'com.google.dagger:dagger:2.14'
annotationProcessor 'com.google.dagger:dagger-compiler:2.14'
kapt 'com.google.dagger:dagger-compiler:2.14'

implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
 }

我的存储库组件:

package com.example.gebruiker.beertime1.di;

 import com.example.gebruiker.beertime1.MainScreen.MainActivity;

  import javax.inject.Singleton;

  import dagger.Component;

  @Component(modules = NetworkModule.class)
  public interface RepositoryComponent {
   void inject(MainActivity mainActivity);
 }
My mainactivity component :

@Component(dependencies = RepositoryComponent.class ,modules = 
{AppModule.class,RepositoryModule.class,NetworkModule.class})
 interface MainActivityComponent{

void inject(MainActivity mainActivity);

 }

2 个答案:

答案 0 :(得分:7)

Dagger 2.14中的known (and fixed) issue。它已在2.14.1中修复,因此这是您应该更新的最低版本。最新版本为2.15,因此您应该更新到那个

答案 1 :(得分:0)

那是a known issue。更新为2.14.1