# Kapt "IllegalStateException: failed to analyze" when encountering a large amount of errors

**URL:** <https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184>\
**Category:** Android\
**Created:** [October 30, 2017, 5:44pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184 "2017-10-30T17:44:42Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![austynm](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@austynm](https://discuss.kotlinlang.org/u/austynm)\
**Post date:** [October 30, 2017, 5:44pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/1 "2017-10-30T17:44:42Z")

</div>

Whenever kapt encounters an annotation processing error in our project (incorrect Dagger annotation, databinding issue, etc.) the underlying exception is not logged to the Gradle console. This makes debugging the underlying issue very time-consuming.

We have artificially created the same Dagger error in our project and a fresh one. In the one without the large amount of annotated classes being processed, the underlying exception is logged correctly.

Most of our errors are Dagger or databinding problems while generating code, which causes the compiler to log a large amount of exceptions (one for every layout or DI annotated class).

```auto
e: {path_redacted}/AppFeedbackActivity.java:17: error: cannot find symbol
e: 

e: private ActivityAppFeedbackBinding mBinding;
e: ^
e: symbol: class ActivityAppFeedbackBinding
e: location: class AppFeedbackActivity
e:
e: public class MainActivity extends ExperticityActivity {
e: ^
e: {path_redacted}/ProfileSettingsActivity.java:22: error: dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.

```

Here is the stack trace that is logged each time no matter the actual problem in our codebase.

```auto
e: java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing
	at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:57)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:138)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:58)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:103)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:386)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:96)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:889)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
	at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:916)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:888)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:385)
	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: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing
	at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:90)
	at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:42)
	at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:205)
	at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:166)
	at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:82)
	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:83)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:377)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:68)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:96)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:368)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:133)
	... 30 more

```

We have the following in our `build.gradle`, increasing the limit above 500 does not resolve the issue.

```auto
gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "500"
    }
}

kapt {
    javacOptions {
        option("-Xmaxerrs", 500)
    }
}

```

Here is all of our version info:

```auto
Kotlin v1.1.51
Android Gradle Plugin v3.0.0
Android Studio v3.0.0

kapt "com.android.databinding:compiler:v3.0.0"
kapt "com.google.dagger:dagger-compiler:v2.7"

```

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [October 31, 2017, 12:53pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/2 "2017-10-31T12:53:03Z")

</div>

Does this still occur when you manually invoke the gradle wrapper? Did you pass the needed parameters to increase gradle verbosity?

---

<div class="post-metadata">

**Author:** ![austynm](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@austynm](https://discuss.kotlinlang.org/u/austynm)\
**Post date:** [October 31, 2017, 5:28pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/3 "2017-10-31T17:28:44Z")

</div>

Yes, the same issue occurs in the console when using `./gradlew build --debug` or `--stacktrace`. Is there anything else you would recommend?

---

<div class="post-metadata">

**Author:** ![Cosecant](https://avatars.discourse-cdn.com/v4/letter/c/6bbea6/32.png) [@Cosecant](https://discuss.kotlinlang.org/u/Cosecant)\
**Post date:** [November 2, 2017, 2:35am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/4 "2017-11-02T02:35:57Z")

</div>

HI，I have this mistake, too. I use android-studio3.0 and android-gradle-3.0.0. When I compile my project , I get this message “java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing” in my gradle console. How can I solve this question? THanks!

---

<div class="post-metadata">

**Author:** ![austynm](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@austynm](https://discuss.kotlinlang.org/u/austynm)\
**Post date:** [November 3, 2017, 12:32am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/5 "2017-11-03T00:32:03Z")

</div>

I spoke with @orangy at KotlinConf today and he suggested I ping @yanex about this issue.

I also spoke with @yeet and he confirmed he has seen a similar issue before, but the fix he had did not work in this case.

Looks like a few other people are encountering the same thing:

> [@Kapt issues with DataBinding](https://discuss.kotlinlang.org/t/kapt-issues-with-databinding/5064/):
>
> \*Binding classes are not generated and I get an Execution failed for task “app:kaptDebugKotlin” error. It may be an issue with other libraries in my app, but i am unable to reach to the point of failure. Following libraries are currently used in project: Dagger 2 RxJava 2 Databinding Kotlin Butterknife Groupie (from lisawray) I made some changes to add dagger.android support, and now i am unable to run the project and the error shows: e: public class OrderBookItem extends Item { e: …

---

<div class="post-metadata">

**Author:** ![Eugene.Beletskiy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/eugene.beletskiy/32/2124_2.png) [@Eugene.Beletskiy](https://discuss.kotlinlang.org/u/Eugene.Beletskiy)\
**Post date:** [November 6, 2017, 5:48pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/6 "2017-11-06T17:48:52Z")

</div>

I’m experiencing the same problem, not sure the problem is caused by a mistake with Dagger like things, as my project builds fine until upgrading Android Gradle Plugin to v3.0.0.

---

<div class="post-metadata">

**Author:** ![yanex](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yanex/32/1489_2.png) [@yanex](https://discuss.kotlinlang.org/u/yanex)\
**Post date:** [November 7, 2017, 1:55am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/7 "2017-11-07T01:55:50Z")

</div>

Well, there are two kinds of `KaptError` exceptions, actually. The one you experience, “Error while annotation processing”, means that the Java compiler and/or some annotation processor logged an error diagnostic message. It _does not mean_ some AP threw an exception.

This message normally can be found _above_ the exception trace you shared. If you have not any error messages there, it’s a kapt bug. (Please share the build log with the `--debug` option specified, and also with `kapt.verbose=true` in the `gradle.properties` file if you can’t share the whole project).  
Note that not all annotation processors pass the proper file location so the error message can be a plain text (without a file/line number).

The other kind of `KaptError` is “Exception while annotation processing”. It typically means some exception is occurred in one of annotation processors. In that case the underlying AP exception should be printed as a ‘cause’.

---

<div class="post-metadata">

**Author:** ![austynm](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@austynm](https://discuss.kotlinlang.org/u/austynm)\
**Post date:** [November 7, 2017, 6:04pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/8 "2017-11-07T18:04:48Z")

</div>

The deprecated original kapt shows the error properly.

Workaround:  
Downgrade to the deprecated version of `kapt` by removing `apply plugin: 'kotlin-kapt'` and then add

```auto
kapt {
    generateStubs = true
    javacOptions {
        option("-Xmaxerrs", 500)
    }
}

```

@yanex Can you give me an email address to share the build log with? Do you want logs from a run of deprecated kapt also?

---

<div class="post-metadata">

**Author:** ![Eugene.Beletskiy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/eugene.beletskiy/32/2124_2.png) [@Eugene.Beletskiy](https://discuss.kotlinlang.org/u/Eugene.Beletskiy)\
**Post date:** [November 7, 2017, 6:30pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/9 "2017-11-07T18:30:31Z")

</div>

The workaround Austynm suggested isn’t working for me. I’m uploading my log, I hope it could help too.[debug.txt.zip](https://discuss.kotlinlang.org/uploads/short-url/nkqEsThfOgfRm2ApautYoOWoSYi.zip) (268.8 KB)

---

<div class="post-metadata">

**Author:** ![yanex](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yanex/32/1489_2.png) [@yanex](https://discuss.kotlinlang.org/u/yanex)\
**Post date:** [November 8, 2017, 3:01am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/10 "2017-11-08T03:01:00Z")

</div>

The original kapt will be removed in 1.2.20, so it not really a solution.

[yan.zhulanow@jetbrains.com](mailto:yan.zhulanow@jetbrains.com).  
Well, it would be nice to see logs both from the old kapt and kapt3.

---

<div class="post-metadata">

**Author:** ![yanex](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yanex/32/1489_2.png) [@yanex](https://discuss.kotlinlang.org/u/yanex)\
**Post date:** [November 8, 2017, 3:03am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/11 "2017-11-08T03:03:15Z")

</div>

Do you mean there is no proper stack trace below the

`class file for com.f2prateek.rx.preferences2.RxSharedPreferences not found`  
`Consult the following stack trace for details.`

error message?

---

<div class="post-metadata">

**Author:** ![Eugene.Beletskiy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/eugene.beletskiy/32/2124_2.png) [@Eugene.Beletskiy](https://discuss.kotlinlang.org/u/Eugene.Beletskiy)\
**Post date:** [November 8, 2017, 7:43am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/12 "2017-11-08T07:43:11Z")

</div>

No, there’s a proper stack trace below the mentioned error, which starts with:

> 19:22:32.070 [ERROR] [org.gradle.api.Task] e: java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing

According to what you said above it seems to be a problem with `kapt`.

---

<div class="post-metadata">

**Author:** ![yanex](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yanex/32/1489_2.png) [@yanex](https://discuss.kotlinlang.org/u/yanex)\
**Post date:** [November 13, 2017, 3:38pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/13 "2017-11-13T15:38:40Z")

</div>

> [@Eugene.Beletskiy](#):
>
> No, there’s a proper stack trace below the mentioned error, which starts with:

@austynm

Well, looks like there should be an another one from javac.  
By the way, did you send the build logs? I’m afraid I didn’t get anything recently.

If you send the logs, please add the `--debug` option, and please also enable verbose output by adding the `kapt.verbose=true` to `gradle.properties`.

---

<div class="post-metadata">

**Author:** ![austynm](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@austynm](https://discuss.kotlinlang.org/u/austynm)\
**Post date:** [November 14, 2017, 1:32am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/14 "2017-11-14T01:32:51Z")

</div>

@yanex I’ve sent the logs to your email, please let me know when you receive them. If you need anything more let me know via Slack or email.

---

<div class="post-metadata">

**Author:** ![yanex](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yanex/32/1489_2.png) [@yanex](https://discuss.kotlinlang.org/u/yanex)\
**Post date:** [November 15, 2017, 9:26am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/15 "2017-11-15T09:26:44Z")

</div>

@austynm I don’t know if this is the only issue that causes this behavior, but here it is: [https://youtrack.jetbrains.com/issue/KT-21264](https://youtrack.jetbrains.com/issue/KT-21264).

---

<div class="post-metadata">

**Author:** ![austynm](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@austynm](https://discuss.kotlinlang.org/u/austynm)\
**Post date:** [November 15, 2017, 9:25pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/16 "2017-11-15T21:25:59Z")

</div>

Glad you found that problem! Let me know when you have a release we can test and I can let you know if it is fixed.

---

<div class="post-metadata">

**Author:** ![davismattg](https://avatars.discourse-cdn.com/v4/letter/d/e36b37/32.png) [@davismattg](https://discuss.kotlinlang.org/u/davismattg)\
**Post date:** [January 31, 2018, 1:36am UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/17 "2018-01-31T01:36:37Z")

</div>

I’m having a similar error trying to use DataBinding with a RecyclerView. My data class is written in Kotlin, everything else in my project is Java. The Gradle Console shows the following error message when I try to build:

```
e: C:\Users\...\app\db\LensListAdapter.java:60: error: cannot find symbol
e: 
e: private LensListBinding binding;
e: ^
e: symbol: class LensListBinding
e: location: class LensListAdapter.LensListViewHolder

```

Android Studio seems to build the Binding classes properly from my layout file (lens\_list.xml). Let me know if there’s anything I can do to help debug this issue.

---

<div class="post-metadata">

**Author:** ![mochadwi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mochadwi/32/5282_2.png) [@mochadwi](https://discuss.kotlinlang.org/u/mochadwi)\
**Post date:** [April 23, 2019, 1:36pm UTC](https://discuss.kotlinlang.org/t/kapt-illegalstateexception-failed-to-analyze-when-encountering-a-large-amount-of-errors/5184/19 "2019-04-23T13:36:26Z")

</div>

any updates on this?
