Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While using dagger 2 : e: [kapt] An exception occurred: java.lang.IllegalArgumentException: void

I am using dagger2 and after adding some view model injection code, I get this error:

e: [kapt] An exception occurred: java.lang.IllegalArgumentException: void
    at com.sun.tools.javac.model.JavacTypes.getDeclaredType0(JavacTypes.java:252)
    at com.sun.tools.javac.model.JavacTypes.getDeclaredType(JavacTypes.java:222)
    at dagger.internal.codegen.langmodel.DaggerTypes.getDeclaredType(DaggerTypes.java:345)
    at dagger.internal.codegen.BindsTypeChecker.desiredAssignableType(BindsTypeChecker.java:71)
    at dagger.internal.codegen.BindsTypeChecker.isAssignable(BindsTypeChecker.java:56)
    at dagger.internal.codegen.BindsMethodValidator$Validator.checkParameter(BindsMethodValidator.java:92)
    at dagger.internal.codegen.BindingMethodValidator$MethodValidator.checkParameters(BindingMethodValidator.java:209)
    at dagger.internal.codegen.BindsMethodValidator$Validator.checkParameters(BindsMethodValidator.java:77)
    at dagger.internal.codegen.BindingMethodValidator$MethodValidator.checkAdditionalProperties(BindingMethodValidator.java:144)
    at dagger.internal.codegen.BindingElementValidator$ElementValidator.validate(BindingElementValidator.java:145)
    at dagger.internal.codegen.BindingElementValidator$ElementValidator.access$000(BindingElementValidator.java:129)
    at dagger.internal.codegen.BindingElementValidator.validateUncached(BindingElementValidator.java:78)
    at dagger.internal.codegen.Util.reentrantComputeIfAbsent(Util.java:93)
    at dagger.internal.codegen.BindingElementValidator.validate(BindingElementValidator.java:74)
    at dagger.internal.codegen.AnyBindingMethodValidator.validateUncached(AnyBindingMethodValidator.java:99)
    at dagger.internal.codegen.Util.reentrantComputeIfAbsent(Util.java:93)
    at dagger.internal.codegen.AnyBindingMethodValidator.validate(AnyBindingMethodValidator.java:74)
    at dagger.internal.codegen.ModuleValidator.validateUncached(ModuleValidator.java:189)
    at dagger.internal.codegen.ModuleValidator.lambda$validate$0(ModuleValidator.java:169)
    at dagger.internal.codegen.Util.reentrantComputeIfAbsent(Util.java:93)
    at dagger.internal.codegen.ModuleValidator.validate(ModuleValidator.java:169)
    at dagger.internal.codegen.ModuleValidator.validate(ModuleValidator.java:163)
    at dagger.internal.codegen.ModuleProcessingStep.process(ModuleProcessingStep.java:98)
    at dagger.internal.codegen.ModuleProcessingStep.process(ModuleProcessingStep.java:47)
    at dagger.internal.codegen.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:51)
    at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:185)
    at dagger.internal.codegen.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:48)
    at dagger.internal.codegen.ModuleProcessingStep.process(ModuleProcessingStep.java:89)
    at dagger.internal.codegen.ModuleProcessingStep.process(ModuleProcessingStep.java:47)
    at dagger.internal.codegen.DaggerStatisticsCollectingProcessingStep.process(DaggerStatisticsCollectingProcessingStep.java:52)
    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.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
    at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:147)
    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.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:79)
    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)
    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)


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> Compilation error. See log for more details

I don't know much about it, why this occurred, but also tried some solution and updating versions of kotlin and dagger2 but didn't work.

Let me know if something else is needed to put in the code.

like image 734
Suraj Vaishnav Avatar asked Oct 06 '19 07:10

Suraj Vaishnav


1 Answers

I just suffered through this exact error. Make sure that you're returning a ViewModel from your module function (provides or binds) e.g.

@Binds
@IntoMap
@ViewModelKey(AuthenticationViewModel::class)
abstract fun bindsAuthViewModel(authViewModel: AuthenticationViewModel) :ViewModel

I'm writing kotlin for the first time in a while and I forgot to add the :ViewModel to return the dependency that'll get injected wherever.

Good luck!

like image 106
bibangamba Avatar answered Oct 19 '22 09:10

bibangamba