question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

See original GitHub issue

If I write code like this by mistake:

class Fragment {
   companion object {
         @Inject
         lateinit var viewModelFactory: ViewModelFactory
   }
   
   // the viewModelFactory injection should by in Fragment code block, not in companion object block

}

Then the Android Studio will build failed, only show “A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution”; even I execute “./gradle assembleDebug --statcktrace”. There is no further more infomation.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
npworkcommented, Apr 5, 2021

My solution was just adding those lines to gradle.properties

kapt.use.worker.api=false
kapt.incremental.apt=false
6reactions
simonsicklecommented, Oct 2, 2020

Ok, so I figured my issue out and wanted to share with everyone just in case you experience the same issue. Basically, this most likely means you have a dependency in your Gradle module that your app module doesn’t know about. So for example you may have the following setup, which Hilt supports.

:app
  - implementation(:api)
  - implementation(:feature1)
:api
  -implementation(okhttp)
:feature1
  - implementation(androidx-stuff)

In api, you may have a class and module like this

class SomeCoolApi @Inject constructor(private val okhttpClient: OkHttpClient) {
    ....
}
...
@Module
@InstallIn(ApplicationComponent::class)
object ApiConfigurationModule {
    @Provides
    @Singleton
    fun getOkHttpClient(): OkHttpClient {
        return OkHttpClient.Builder().build()
    }
}

This is all fine, and accomplishes your goal of having a singleton for your OKHttp client for use in other parts of your app. The problem comes now, your app module which contains all of the hilt checks and final setup doesn’t know of this code, it has no clue what OkHttp is.

You can fix this compile error by either setting implementation into api, so that it becomes a transitive dependency, disable transitive dependency validation, or add the dependency as implementation() to your app module. I personally did the last option, as api() was causing slower builds for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A failure occurred while executing org.jetbrains.kotlin.gradle ...
In Android studio go to Analyze menu and click on Inspect Code; check whole project, click OK and wait for the inspection to...
Read more >
A failure occurred while executing org ... - JetBrains YouTrack
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution > java.lang.reflect.InvocationTargetException (no error message) ...
Read more >
Kotlin 1.7.0 - A failure occurred while executing org.jetbrains ...
Execution failed for task ':presentation:kaptDebugKotlin'. A failure occurred while executing org.jetbrains.kotlin.gradle.internal.
Read more >
A failure occurred while executing org.jetbrains.kotlin.gradle ...
Android : A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.
Read more >
A failure occurred while executing org.jetbrains.kotlin.gradle ...
Recently I got this error :. A failure occurred while executing org.jetbrains.kotlin.gradle.internal.kaptexecution. ? How can I solve this ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found