当我试图使用kapt将一个安卓项目迁移到KSP时,我会收到一条错误消息。
错误消息
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.目前,以下库正在使用kapt。
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"
}有关更多细节,回购程序托管在这里- https://github.com/Abhimanyu14/finance-manager。
发布于 2022-06-25 16:52:02
正如问题中提到的,我正在使用以下使用kapt的库。
从KSP文档中,我发现Hilt还不受支持。(截至25-06-2022)。
因此,我需要在我的项目中同时使用kapt和hilt。
下面的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"库版本
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"也遇到了这个错误- 未向注释处理器提供房间模式导出目录,因此无法导出架构。
这个解决方案也有帮助- https://stackoverflow.com/a/71451314/9636037
ksp {
arg('room.schemaLocation', "$projectDir/schemas")
}https://stackoverflow.com/questions/72751875
复制相似问题