Error:Execution failed for task ':app:kaptDebugKotlin'

AndroidKotlinDagger 2

Android Problem Overview


I'm new to using Kotlin and trying to set it up with Dagger2, I've seen some few examples but none of them seem to work for me.

I keep getting this

> Error:Execution failed for task ':app:kaptDebugKotlin'. > > Internal compiler error. See log for more details

I have my build.gradle (Module: app)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.exampleapp"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    kapt {
        generateStubs = true
    }
    dexOptions {
        javaMaxHeapSize "2048M"
    }
}

ext {
    supportLibVer = '25.0.0'
    daggerVer = '2.8'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Support lib
    compile "com.android.support:appcompat-v7:${supportLibVer}"

    kapt "com.google.dagger:dagger-compiler:${daggerVer}"
    compile "com.google.dagger:dagger:${daggerVer}"
    provided "javax.annotation:jsr250-api:${javaxVer}"

    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"


}
repositories {
    mavenCentral()
}

Android Solutions


Solution 1 - Android

Run your application with ./gradlew clean build command to see what's exactly wrong with your code. Just paste it into the Terminal in Android Studio.

Solution 2 - Android

If you are using the Room database and getting a KAPT error, just check your

  1. Database declarations
  2. Data Access Object declarations
  3. Data class fields

It's a problem arising due to improper usage of annotations of Room. For more information use your build logs.

You can see here in this picture before expanding the error log, I can see the annotation missing error.

Solution 3 - Android

I faced this problem for a while. What helped me a lot was reading the build tab because it gave the reasons the library was failing.
Here is the tab Build tab I had many problems,

  1. I haven't added the new entity I created into the @Database annotation
  2. I haven't added the @Dao annotation in my interface
  3. I haven't updated some variables names that was wrote in a @Query annotation
    So I had to kill problem by problem, finally it could run later. In Addition, I was cleaning my project and rebuilding to ensure code doesn't get stuck. Also close and open Android Studio.

Futhermore, you can check this answer to help you find the error enable more log on error

Solution 4 - Android

I faced this problem for a while. My mistake was using private access specifier with @Inject field.

If you are using Dagger then check for @Inject private fields or to know the exact cause add this as Command-line options:

--stacktrace --info --scan

On Mac, go to Android Studio > Preferences > Build, Execution, Deployment > Compiler

On Windows, go to File > Settings > Build, Execution, Deployment > Compiler

Solution 5 - Android

In my case, I forgot to add the room db entities to the database

@Database(version = 1,
    entities = [DummyEntity::class]
 )

Solution 6 - Android

Issue can be connected with Room and Kotlin 1.4.10.

Try to change android.arch.persistence to androidx.room for Room dependencies:

Use

kapt "androidx.room:room-compiler:$roomVersion"

instead of

kapt "android.arch.persistence.room:compiler:$roomVersion"

Solution 7 - Android

In my case I replaced this

implementation 'com.google.dagger:dagger:2.27'
kapt 'com.google.dagger:dagger-compiler:2.27'

by

implementation 'com.google.dagger:dagger:2.27'
annotationProcessor "com.google.dagger:dagger-compiler:2.27"

and solved the problem

Solution 8 - Android

If You are using Hilt and Field Injection Then Remove Private From Field Injected Object this worked For me

    @Inject
    private lateinit var helper: Helper

to

    @Inject
    lateinit var helper: Helper

Solution 9 - Android

Worked for me:

I also had the same problem and solved it by adding this to gradle.properties

org.gradle.java.home=<go to project structure, copy JDK location and past here>

This ensures that gradlew uses the same JDK as Android Studio

Solution 10 - Android

The issue is probably related to the use of Room. I used the command Łukasz Kobyliński suggested in his comment

> ./gradlew clean build

and in my case I had to add a converter for Date type.

You can find the converter in the official docs: https://developer.android.com/training/data-storage/room/referencing-data#type-converters

Solution 11 - Android

my mistake was using suspend when then function returns LiveData.Room's coroutines integration brings ability to return suspend values but when the value itself is asnyc, there is no reason to use it. i changed :

@Delete
suspend fun Delete(premiumPackageDBEntity: PremiumPackageDBEntity)

@Query("SELECT * FROM available_premium_package ")
suspend fun GetAll(): LiveData<List<PremiumPackageDBEntity>>

to :

@Delete
suspend fun Delete(premiumPackageDBEntity: PremiumPackageDBEntity)

@Query("SELECT * FROM available_premium_package ")
fun GetAll(): LiveData<List<PremiumPackageDBEntity>>

and the problem solved.

Solution 12 - Android

In my case, I forgot to add newly created entities into "entities" section of @Database declaration using Room library.

--stacktrace --info --scan commandline options are a great help to find the exact cause.

Solution 13 - Android

I just faced a similar bug. If you're using an old dependency for Room, update and rebuild your project.

Solution 14 - Android

I faced similar problem when setting up dagger2. It was finally resolved when I changed this line:

kapt "com.google.dagger:dagger-compiler:${daggerVer}"

to this

annotationProcessor "com.google.dagger:dagger-compiler:${daggerVer}"

Solution 15 - Android

I have solved this problem. In my case, there were irrelevant dagger 
dependencies 
that the IDE did not notify me about:

   implementation 'com.google.dagger:dagger:2.35.1'
   kapt 'com.google.dagger:dagger-compiler:2.28'

After updating them, the problem disappeared and it became possible to use the 
latest version of Kotlin!

   implementation 'com.google.dagger:dagger:2.37'
   kapt 'com.google.dagger:dagger-compiler:2.37'

Solution 16 - Android

if all that tasks are not work, just run your app. You will see error log clearly.

Solution 17 - Android

For me I deleted these folders.

  1. .gradle
  2. .idea

> Close android studio , delete the folders and reopen the project

enter image description here

Solution 18 - Android

First change

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

to

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Now you have to tweak your project Gradle file and update the version of Kotlin being used which should be something like below:

ext { kotlin_version = '1.3.10' gradleVersion = '3.1.0' }

Solution 19 - Android

I got the same error and solved it simply by following these steps

1- open File menu -> then choose Project Structure or press Ctrl+Alt+Shift+s

2- open Modules from the left

3- In Source Compatibility press the drop down menu and choose Java 8 or 1.8

4- In Target Compatibility press the drop down menu and choose Java 8 or 1.8

5- press ok then sync and rebuild your project or run it

Solution 20 - Android

In my case build.gradle replaced
id 'kotlin-android-extensions' to id 'kotlin-parcelize' as it said on build

added

buildFeatures {
        viewBinding true
    }

also had a few syntax mistakes like forgetting : at Dao

@Query("SELECT * FROM table_satis WHERE satisId ==:satisID")

Solution 21 - Android

In my case I'm using ViewBinding instead of DataBinding. And when I got the same problem I solved it with adding plugin apply plugin: 'kotlin-parcelize' to gradle.

Solution 22 - Android

try add to gradle.properties:

kapt.use.worker.api=false
kapt.incremental.apt=false

Solution 23 - Android

I wrote accidentally @EntryPoint instead of @AndroidEntryPoint. Changing that error was fixed.

Solution 24 - Android

I faced a similar problem. It was resolved when I changed this line:

ext.kotlin_version = "1.5.10"

to

ext.kotlin_version = "1.4.10"

Solution 25 - Android

In some of the Cases if the id of the View is incorrect it always shows this error.Recheck if the id of the view is correct.

Solution 26 - Android

In my case, i just updated the recently added dependencies(a newer version was available), and it worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionleggoView Question on Stackoverflow
Solution 1 - AndroidŁukasz KobylińskiView Answer on Stackoverflow
Solution 2 - AndroidWilley HuteView Answer on Stackoverflow
Solution 3 - Androidjan4coView Answer on Stackoverflow
Solution 4 - AndroidJatin SachdevaView Answer on Stackoverflow
Solution 5 - AndroidSangeetha SakthivelView Answer on Stackoverflow
Solution 6 - Androidmiel3kView Answer on Stackoverflow
Solution 7 - AndroidWad HannouchView Answer on Stackoverflow
Solution 8 - Androidgulab patelView Answer on Stackoverflow
Solution 9 - AndroidDevenView Answer on Stackoverflow
Solution 10 - AndroidIván FerrantView Answer on Stackoverflow
Solution 11 - AndroidmhKaramiView Answer on Stackoverflow
Solution 12 - AndroidMohKView Answer on Stackoverflow
Solution 13 - AndroidVictor LovedayView Answer on Stackoverflow
Solution 14 - AndroidAustin ChangView Answer on Stackoverflow
Solution 15 - Androidfazal ur RehmanView Answer on Stackoverflow
Solution 16 - AndroidYıldırımView Answer on Stackoverflow
Solution 17 - AndroidQuick learnerView Answer on Stackoverflow
Solution 18 - AndroidPedifView Answer on Stackoverflow
Solution 19 - AndroidAhmedView Answer on Stackoverflow
Solution 20 - AndroidSamirView Answer on Stackoverflow
Solution 21 - AndroidMaxBView Answer on Stackoverflow
Solution 22 - AndroidamironView Answer on Stackoverflow
Solution 23 - AndroidKatarina VuknicView Answer on Stackoverflow
Solution 24 - AndroidVinithiusView Answer on Stackoverflow
Solution 25 - AndroidKartik SetiaView Answer on Stackoverflow
Solution 26 - AndroidShubham SharmaView Answer on Stackoverflow