我繼續運行我的應用程式,它一直顯示以下錯誤:
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)
該應用程式無法在我的手機上啟動。我試圖清理專案并運行 ./gradlew clean 但仍然遇到相同的錯誤。應用程式構建成功,但無法運行。以下是我的專案級 gradle 檔案:
buildscript {
ext.kotlin_version = '1.7.0-RC2'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
以下是我的應用程式級 gradle 檔案:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdk 32
defaultConfig {
applicationId "com.schatzdesigns.mobileloanappuiconcept"
minSdkVersion 16
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
buildToolsVersion '33.0.0 rc2'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.0-alpha04'
implementation 'androidx.core:core-ktx:1.9.0-alpha04'
implementation 'com.google.android.material:material:1.7.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.vectordrawable:vectordrawable:1.2.0-beta01'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-rc01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
//noinspection LifecycleAnnotationProcessorWithJava8
kapt 'androidx.lifecycle:lifecycle-compiler:2.5.0-rc01'
implementation 'com.google.dagger:dagger:2.35.1'
implementation 'com.google.dagger:dagger-android:2.35.1'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.5.0-alpha04'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0-alpha07'
}
kapt {
generateStubs = false
}
uj5u.com熱心網友回復:
問題是您使用不同版本的 dagger-android 和 dagger-processor 導致 kapt 問題。
嘗試使用這個:
implementation 'com.google.dagger:dagger:2.21'
implementation 'com.google.dagger:dagger-android:2.16'
implementation 'com.google.dagger:dagger-android-support:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
或者,如果您需要升級匕首版本,請嘗試使用Dagger 2 Releases中的升級指南或升級到 Dagger Hilt。
uj5u.com熱心網友回復:
我在將 Kotlin 版本升級到 1.7.0 時遇到了這個問題
修復 - 將匕首版本更新到最新版本 - 2.42
實施“com.google.dagger:dagger:2.42”
kapt "com.google.dagger:dagger-compiler:2.42"
查找最新的匕首版本 - https://github.com/google/dagger/releases
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/490140.html
上一篇:FirebaseApp未初始化
