升级到Android Studio Arctic Fox后,现在我被卡在了“Execution failed for task ':app:kaptDebugKotlin'”这个错误上。

8

我刚在Mac上更新到了Android Studio Arctic Fox版本,更新后需要修复并更新所有Gradle配置以使其与Gradle 7.0兼容并满足新版本的要求,但是在构建我的项目时却遇到了这个错误:

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

供参考,这是我的项目 Gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        kotlin_version = "1.5.21"
        version_navigation = "2.3.5"
        version_lifecycle_extensions = "2.2.0"
        version_lifecycle = "2.3.1"
        version_room = "2.4.0-alpha04"
        //version_room = "2.2.6"
        version_coroutine = "1.5.0"
        version_retrofit = "2.9.0"
        version_moshi = "1.9.3"
        version_retrofit_coroutines_adapter = "0.9.2"
        version_glide = "4.12.0"
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        classpath 'com.android.support:multidex:1.0.3'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

这是我的模块Gradle文件:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id "org.jetbrains.kotlin.kapt"
    //id 'androidx.navigation.safeargs'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.virtualsheetmusic.vsheetmusic"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 20
        versionName "2.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        multiDexEnabled true

        vectorDrawables.useSupportLibrary = 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 = '1.8'
    }

    buildFeatures {

        //dataBinding includes viewBidning below https://dev59.com/oVMH5IYBdhLWcg3w1TuK
        dataBinding true

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

dependencies {

    //implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    //implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    //implementation "org.jetbrains.kotlin:kotlin-android-extensions-runtime:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation "androidx.fragment:fragment-ktx:1.3.6"
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'

    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.jakewharton.timber:timber:4.7.1'

    //Lifecycle and LiveData
    implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle"

    //Room
    implementation "androidx.room:room-runtime:$version_room"
    kapt "androidx.room:room-compiler:$version_room"//annotationProcessor

    // Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:$version_room"


    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version_coroutine"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version_coroutine"

    // Testing
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    //For Internet connectiona and JSON stuff...

    // Moshi
    implementation "com.squareup.moshi:moshi:$version_moshi"
    implementation "com.squareup.moshi:moshi-kotlin:$version_moshi"

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$version_retrofit"
    //implementation "com.squareup.retrofit2:converter-scalars:$version_retrofit"

    // Retrofit with Moshi Converter
    implementation "com.squareup.retrofit2:converter-moshi:$version_retrofit"
    implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:$version_retrofit_coroutines_adapter"

    //Glide
    implementation "com.github.bumptech.glide:glide:$version_glide"
    kapt "com.github.bumptech.glide:compiler:$version_glide"

    //Recyclerview swipe-refresh...
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

    //For PDF and download management from here: https://blog.mindorks.com/how-to-open-a-pdf-file-in-android-programmatically
    //https://github.com/barteksc/AndroidPdfViewer
    //implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
    //implementation 'com.mindorks.android:prdownloader:0.6.0'

    //This below to handle double clicks...
    //implementation 'com.gitlab.developerdeveloperdeveloper:androidutilslibrary:1.0.0'

}

我也尝试通过命令行调试问题,执行"./gradlew clean build",以下是输出结果:
> Configure project :app
Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.

> Task :app:stripDebugDebugSymbols
Unable to strip the following libraries, packaging them as they are: libc++_shared.so, libjniPdfium.so, libmodft2.so, libmodpdfium.so, libmodpng.so.

> Task :app:stripReleaseDebugSymbols
Unable to strip the following libraries, packaging them as they are: libc++_shared.so, libjniPdfium.so, libmodft2.so, libmodpdfium.so, libmodpng.so.

> Task :app:extractReleaseNativeSymbolTables
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips/libmodpng.so because unable to locate the objcopy executable for the mips ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips/libmodft2.so because unable to locate the objcopy executable for the mips ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips/libc++_shared.so because unable to locate the objcopy executable for the mips ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips/libmodpdfium.so because unable to locate the objcopy executable for the mips ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips/libjniPdfium.so because unable to locate the objcopy executable for the mips ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/armeabi-v7a/libmodpng.so because unable to locate the objcopy executable for the armeabi-v7a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/armeabi-v7a/libmodft2.so because unable to locate the objcopy executable for the armeabi-v7a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/armeabi-v7a/libc++_shared.so because unable to locate the objcopy executable for the armeabi-v7a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/armeabi-v7a/libmodpdfium.so because unable to locate the objcopy executable for the armeabi-v7a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/armeabi-v7a/libjniPdfium.so because unable to locate the objcopy executable for the armeabi-v7a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips64/libmodpng.so because unable to locate the objcopy executable for the mips64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips64/libmodft2.so because unable to locate the objcopy executable for the mips64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips64/libc++_shared.so because unable to locate the objcopy executable for the mips64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips64/libmodpdfium.so because unable to locate the objcopy executable for the mips64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/mips64/libjniPdfium.so because unable to locate the objcopy executable for the mips64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86/libmodpng.so because unable to locate the objcopy executable for the x86 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86/libmodft2.so because unable to locate the objcopy executable for the x86 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86/libc++_shared.so because unable to locate the objcopy executable for the x86 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86/libmodpdfium.so because unable to locate the objcopy executable for the x86 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86/libjniPdfium.so because unable to locate the objcopy executable for the x86 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libmodpng.so because unable to locate the objcopy executable for the arm64-v8a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libmodft2.so because unable to locate the objcopy executable for the arm64-v8a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libc++_shared.so because unable to locate the objcopy executable for the arm64-v8a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libmodpdfium.so because unable to locate the objcopy executable for the arm64-v8a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libjniPdfium.so because unable to locate the objcopy executable for the arm64-v8a ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86_64/libmodpng.so because unable to locate the objcopy executable for the x86_64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86_64/libmodft2.so because unable to locate the objcopy executable for the x86_64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86_64/libc++_shared.so because unable to locate the objcopy executable for the x86_64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86_64/libmodpdfium.so because unable to locate the objcopy executable for the x86_64 ABI.
Unable to extract native debug metadata from /Volumes/DocumentsNew/Users/fabrizio/AndroidStudioProjects/VSheetMusic/app/build/intermediates/merged_native_libs/release/out/lib/x86_64/libjniPdfium.so because unable to locate the objcopy executable for the x86_64 ABI.

> Task :app:kaptDebugKotlin FAILED
> Task :app:kaptReleaseKotlin FAILED

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:kaptReleaseKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 15s
69 actionable tasks: 68 executed, 1 up-to-date

我已经花了数小时来解决这个问题,所以如果你有任何想法,请告诉我!

提前感谢大家。

6个回答

3
问题已解决,经过进一步研究并使用命令行构建以获得更多的调试信息(我使用了./gradlew clean build --stacktrace),我发现Kapt和JDK 16存在问题,如此处所述:https://youtrack.jetbrains.com/issue/KT-45545
我按照那里的建议添加了:
org.gradle.jvmargs=--illegal-access=permit

修改gradle.properties文件后,问题得到解决!


org.gradle.jvmargs=--illegal-access=permit并不是一个好主意,因为JDK 17(2021年9月)已经说明:https://openjdk.java.net/jeps/403#Description:~:text=我们预计将在未来的版本中完全删除--illegal-access选项。 - IainCunningham
如果您在Youtrack.kotlin中链接的线程中继续向下查看,您会发现如果使用JDK17,KAPT存在许多(未解决的)问题(您还会看到KAPT团队正在努力解决这些问题)。目前已知的唯一解决方法是:1.不要使用JDK>16,2.按照https://youtrack.jetbrains.com/issue/KT-45545#focus=Comments-27-4862682.0-0中所述使用`--add-opens`。 - IainCunningham

0
经过尝试不同的方法,我发现你需要在build.gradle文件中的所有项目(而不是模块中的文件)中添加google()和mavenCentral()存储库。将以下内容添加到Project下的build.gradle文件中,然后同步你的项目。
allprojects {
 repositories {
    google()
    mavenCentral()
  }
}

0
设置NDK版本,以便"提取本机调试元数据":
android {
    ndkVersion '21.3.6528147'
    compileSdk 32
    ...
}

0

我在我的 Mac M1 上遇到了同样的问题。 问题是由于使用 room 导致的 :

implementation "androidx.room:room-runtime:2.3.0"
kapt "org.xerial:sqlite-jdbc:3.34.0"
kapt "androidx.room:room-compiler:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"

我在这里找到了一个解决方法:https://youtrack.jetbrains.com/issue/DBE-12342。你需要在你的build.gradle文件中添加以下内容来添加JDBC驱动程序:
kapt "org.xerial:sqlite-jdbc:3.34.0"

谢谢,下次出现同样的问题我会尝试这个方法。 - Fabrizio Ferrari

-1

为了消除那个错误,以便在编译时能够看到真正的问题,解决方案是将VERSION_1_8更改为VERSION_11

compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
}

android 代码块内部


-1

只需在项目级别的gradle中更新您的kotlin依赖版本。


我已经有最新的版本了:1.5.21(请参见上面我的项目Gradle文件)。或者我误解了你的建议? - Fabrizio Ferrari
我的错误,最新版本是1.5.30,如此解释:https://plugins.gradle.org/plugin/org.jetbrains.kotlin.android 但仍然失败,同样的错误! - Fabrizio Ferrari
请尝试使用 Kotlin 1.4.32 版本,这个版本对我来说是可行的。 - Deepak Vajpayee
谢谢,但我通过在gradle.properties文件中添加org.gradle.jvmargs=--illegal-access=permit来解决了它(请参见我的上面的答案)。谢谢! - Fabrizio Ferrari
注意:org.gradle.jvmargs=--illegal-access=permit将从JDK中删除(第一步大约在2021年9月左右进行) https://openjdk.java.net/jeps/403#Description:~:text=我们预计在未来的一个版本中完全删除--illegal-access选项 - IainCunningham
谢谢您的留言。这是否意味着我仍然会被困在同样的问题中? - Fabrizio Ferrari

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