简体   繁体   English

Kapt 到 KSP 迁移错误

[英]Kapt to KSP migration errors

I am getting an error message when I try to migrate an android project using kapt to KSP .当我尝试使用kapt将 android 项目迁移到KSP时,我收到一条错误消息。

Error message错误信息

Unable to find method ''void org.jetbrains.kotlin.gradle.tasks.KotlinCompile.<init>(org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions)''
'void org.jetbrains.kotlin.gradle.tasks.KotlinCompile.<init>(org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions)'

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Currently, the following libraries are using kapt .目前,以下库正在使用kapt

  1. Moshi莫希
  2. Hilt刀柄
  3. Room房间

build.gradle

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "kotlin-kapt"
    id "dagger.hilt.android.plugin"
    id "com.google.devtools.ksp" version "1.6.10-1.0.4"
}

dependencies {

    // Hilt
    implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
    kapt "com.google.dagger:hilt-compiler:$rootProject.hiltVersion"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:$rootProject.hiltLifecycleViewModelVersion"
    kapt "androidx.hilt:hilt-compiler:$rootProject.hiltCompilerVersion"

    // KSP
    // implementation "com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.4"

    // Moshi
    implementation "com.squareup.moshi:moshi:$rootProject.moshiVersion"
    implementation "com.squareup.moshi:moshi-kotlin:$rootProject.moshiKotlinVersion"
    kapt "com.squareup.moshi:moshi-kotlin-codegen:$rootProject.moshiKotlinCodegenVersion"
    // ksp "com.squareup.moshi:moshi-kotlin-codegen:1.13.0"

    // Room
    implementation "androidx.room:room-runtime:$rootProject.roomVersion"
    implementation "androidx.room:room-ktx:$rootProject.roomVersion"
    annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"
    ksp "androidx.room:room-compiler:$rootProject.roomVersion"
    androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
}

For more details, The repo is hosted here - https://github.com/Abhimanyu14/finance-manager有关更多详细信息,该 repo 托管在这里 - https://github.com/Abhimanyu14/finance-manager

As mentioned in the question, I am using the following libraries that are using kapt .如问题中所述,我正在使用以下使用kapt的库。

  1. Moshi莫希
  2. Hilt刀柄
  3. Room房间

From the KSP Docs , I found out Hilt is not yet supported.KSP Docs中,我发现Hilt尚不受支持。 (as of 25-06-2022). (截至 2022 年 6 月 25 日)。

So, I would need to use both kapt and hilt in my project.所以,我需要在我的项目中同时使用kapthilt


The following build.gradle does that,下面的build.gradle做到了,

plugins {
    id "kotlin-kapt"
    id "dagger.hilt.android.plugin"
    id "com.google.devtools.ksp" version "1.6.21-1.0.6"
}

// Hilt
implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-compiler:$rootProject.hiltVersion"
//ksp "com.google.dagger:hilt-compiler:$rootProject.hiltVersion"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$rootProject.hiltLifecycleViewModelVersion"
kapt "androidx.hilt:hilt-compiler:$rootProject.hiltCompilerVersion"
// ksp "androidx.hilt:hilt-compiler:$rootProject.hiltCompilerVersion"

// KSP
implementation "com.google.devtools.ksp:symbol-processing-api:1.6.21-1.0.6"

// Moshi
implementation "com.squareup.moshi:moshi:$rootProject.moshiVersion"
implementation "com.squareup.moshi:moshi-kotlin:$rootProject.moshiKotlinVersion"
// kapt "com.squareup.moshi:moshi-kotlin-codegen:$rootProject.moshiKotlinCodegenVersion"
ksp "com.squareup.moshi:moshi-kotlin-codegen:1.13.0"preferences:$rootProject.datastorePreferencesVersion"

// Room
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"
// kapt "androidx.room:room-compiler:$rootProject.roomVersion"
ksp "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

Library versions库版本

roomVersion = "2.5.0-alpha02"
moshiVersion = "1.13.0"
hiltVersion = "2.42"
hiltPluginVersion = "2.40.1"
hiltLifecycleViewModelVersion = "1.0.0-alpha03"
hiltCompilerVersion = "1.0.0"

Also encountered this error - Room - Schema export directory is not provided to the annotation processor so we cannot export the schema也遇到了这个错误 - Room - 模式导出目录未提供给注释处理器,因此我们无法导出模式

And this solution helped - https://stackoverflow.com/a/71451314/9636037这个解决方案有帮助 - https://stackoverflow.com/a/71451314/9636037

ksp {
    arg('room.schemaLocation', "$projectDir/schemas")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 kapt3构建生成的错误 - kapt3 build generated errors 添加kapt以使用Room会导致编译错误 - Adding kapt to use Room causes compile errors 为什么添加kotlin kapt后会产生不清楚的错误? - Why unclear errors are generated after adding kotlin kapt? 使用新的kotlin 1.1构建错误,kapt cant parse databinding params - Build errors with new kotlin 1.1 , kapt cant parse databinding params 使用“ kotlin-kapt”插件,Android Studio不会提供有关Dagger 2的特定错误 - With 'kotlin-kapt' plugin, Android Studio doesnt provide specific errors about Dagger 2 为什么我的错误被Kapt和Kotlin埋葬了? 如何增加错误限制? - Why are my errors getting buried with Kapt and Kotlin? How do I increase the error limit? 从Android Studio运行时,Kotlin Kapt不会显示数据绑定错误 - Kotlin Kapt doesn't show databinding errors when running from Android Studio e: [kapt] 发生异常:android.databinding.tool.util.LoggedErrorException: 发现数据绑定错误 - e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors 迁移到 AndroidX 后的一些错误 - some Errors after migration to AndroidX 拦截房间迁移错误以重新创建数据库 - Intercepting room migration errors to recreate the DB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM