Error:Execution failed for task ':app:kaptDebu

2019-04-07 05:56发布

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()
}

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-07 06:21

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' }

查看更多
老娘就宠你
3楼-- · 2019-04-07 06:26

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.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-04-07 06:37

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

查看更多
登录 后发表回答