执行org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction时发生了故障?java.lang.reflect.Invocation?

7

当我在真机上运行Android应用程序时,我遇到了以下Gradle错误。

Execution failed for task ':common:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

以下是我的app.gradle文件

    plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'kotlin-kapt'

apply from: '../commons.gradle'

android {
    compileSdkVersion 30
    buildFeatures {

        dataBinding = true

        // for view binding:
        // viewBinding = true
    }

    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.androidcodingchallenge"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables{
            useSupportLibrary = true
        }

        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

dependencies {
    implementation project(':data')
    implementation project(':domain')
    implementation project(':presentation')
    implementation project(':remote')
    implementation project(':cache')
    implementation project(':common')
    implementation project(':device')

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation "com.google.android.material:material:$material_version"

    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    implementation 'androidx.cardview:cardview:1.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    //navigation component
//    implementation "androidx.navigation:navigation-fragment-ktx:2.3.2"
//    implementation "androidx.navigation:navigation-ui-ktx:2.3.2"

    // UI
    implementation "com.github.bumptech.glide:glide:$glide_version"
    kapt "com.github.bumptech.glide:compiler:$glide_version"

    // Ktx
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
    implementation "androidx.fragment:fragment-ktx:1.3.0"

    // Navigation
    implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation"
    implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation"

    //viewpager2
    implementation "androidx.viewpager2:viewpager2:1.0.0"

    implementation 'com.thoughtbot:expandablerecyclerview:1.3'
    implementation 'com.thoughtbot:expandablecheckrecyclerview:1.4'

    //indicator
    implementation 'me.relex:circleindicator:2.1.4'
    //lottie
    implementation "com.airbnb.android:lottie:3.4.1"
    //datastore
    implementation "androidx.datastore:datastore-preferences:1.0.0-alpha06"

    implementation 'androidx.hilt:hilt-navigation-fragment:1.0.0-alpha03'

    //LeakCanary
    debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"

    //Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    //multidex
    implementation 'com.android.support:multidex:1.0.3'

}

下面是 commons.gradle。

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'

androidExtensions {
    experimental = true
}

android {
//    compileSdkVersion Versions.compileSdkVersion
//    buildToolsVersion Versions.buildTool
//    defaultConfig {
//        minSdkVersion Versions.minSdk
//        targetSdkVersion Versions.targetSdk
//        versionCode Releases.versionCode
//        versionName Releases.versionName
//        vectorDrawables.useSupportLibrary = true
//    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    kapt {
        javacOptions {
            // Increase the max count of errors from annotation processors.
            // Default is 100.
            option("-Xmaxerrs", 500)
        }
        // Configure kapt to correct error types for Hilt
        correctErrorTypes true
    }

    buildFeatures{
        dataBinding = true
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    lintOptions {
        abortOnError false
    }

    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    //Loads packaged libraries in the libs folder
    implementation fileTree(dir: 'libs', include: ['*.jar'])

//    implementation KotlinLibraries.kotlin
//    implementation AndroidLibraries.coreKtx
//
//    implementation Libraries.hilt
//    implementation Libraries.hiltJetpack
//    kapt Libraries.hiltCompiler
//    kapt Libraries.hiltJetpackCompiler
//
//    // For instrumentation tests
//    androidTestImplementation Libraries.hiltAndroidTest
//    kaptAndroidTest Libraries.hiltAndroidTestCompiler
//
//    // For local unit tests
//    testImplementation Libraries.hiltAndroidUnitTest
//    kaptTest Libraries.hiltAndroidUnitTestCompiler
//
//    implementation TestLibraries.androidTestRunner
//    implementation TestLibraries.junit
//    implementation TestLibraries.espresso
//    implementation TestLibraries.espressoContrib

    // Concurrency
    implementation "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
    implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"


    //Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_androidx_version"
    kapt "androidx.hilt:hilt-compiler:$hilt_androidx_version"

    // Utils
    implementation "com.jakewharton.threetenabp:threetenabp:$threetenabp_version"


}

以下是 build.gradle 文件

buildscript {
    ext{
        kotlin_version = "1.4.20"
        version_navigation = "2.3.5"
        hilt_version = '2.31.2-alpha'

        version_navigation = "2.3.5"
        version_lifecycle_extensions = "2.2.0"
        lifecycle_version = "2.2.0"
        hilt_androidx_version = "1.0.0-alpha03"

        material_version = "1.3.0"

        coroutines_version = "1.4.1"

        junit_version = "4.13"

        retrofit_version = "2.9.0"
        okHttp_version = "4.9.0"
        moshi_converter_version = '2.9.0'
        moshi_version = '1.11.0'

        mockwebserver_version = "4.9.0"
        robolectric_version = "4.4"
        mockito_version = "3.5.15"
        google_truth_version = "1.0"
        coroutines_test = "1.3.1"

        room_version = "2.3.0"

        threetenabp_version = "1.2.4"
        leakcanary_version = "2.4"
        timber_version = "4.7.1"

        glide_version = "4.11.0"
        androidsvg_version = "1.4"

        rxkotlin_version = "2.4.0"
        rxandroid_version = "2.1.1"

        google_services_version = "4.3.8"
    }

    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"

        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        classpath "com.google.gms:google-services:$google_services_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我尝试了清除缓存和重启,跟着这个问题跟踪器做了所有建议的答案,但仍然没有解决我的问题。此外,在Android Studio中运行gradlew clean时出现以下错误:FAILURE: Build completed with 2 failures。

1:任务执行异常。

  • 出错了: 执行任务':common:kaptDebugKotlin'失败。

执行org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$ KaptExecutionWorkAction时发生故障 java.lang.reflect.InvocationTargetException(无错误消息)

  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。 使用--info或--debug选项运行以获取更多日志输出。 使用--scan运行以获取完整的洞察力。 ==============================================================================

2:任务执行异常。

  • 出错了: 执行任务':common:kaptReleaseKotlin'失败。

执行org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$ KaptExecutionWorkAction时发生故障 java.lang.reflect.InvocationTargetException(无错误消息)

  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。 使用--info或--debug选项运行以获取更多日志输出。 使用--scan运行以获取完整的洞察力。 ==============================================================================

请注意,我正在使用Android Studio Arctic Fox。

我想知道我到底做错了什么。

1个回答

2

我通过将当前的Kotlin版本更新到最新版本,并将Moshi版本更新到1.12.0来解决了我的问题。


1
这里的Moshi是什么? - Yash
1
你的修复是什么? - Raghu Krishnan R
1
它不起作用! - Jorgesys

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接