【问题标题】:Error ':app:compileDebugKotlin' java.lang.reflect.InvocationTargetException after migrating to Androidx迁移到 Androidx 后出现错误 ':app:compileDebugKotlin' java.lang.reflect.InvocationTargetException
【发布时间】:2021-01-27 06:40:37
【问题描述】:

在我迁移我的项目后,出现了一些错误,比如数据绑定等等,但我已经解决了,然后错误变成了这个:

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

我尝试了很多解决方案,比如将 kotlin 版本更新到 1.4.20,还有一些消息来源要求我升级房间版本,所以我将它更新到最新版本,但结果都失败了。

这是我的 gradle 模块:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.jakewharton.butterknife'

android {

compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
    applicationId "my package"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode 1
    versionName "1.18"
    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

dexOptions {
    javaMaxHeapSize "4g"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
}
packagingOptions {
    exclude 'META-INF/rxjava.properties'
}

buildFeatures {
    dataBinding = true
}

}

 dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core:1.3.2'
implementation 'com.jakewharton:butterknife:10.2.3'
kapt 'com.jakewharton:butterknife-compiler:10.2.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'

implementation 'jp.wasabeef:blurry:2.1.1'
implementation 'jp.wasabeef:fresco-processors:2.1.0'

implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.github.IntruderShanky:Sectioned-RecyclerView:2.1.1'
implementation 'id.zelory:compressor:2.1.0'


implementation 'com.github.rey5137:material:1.2.2'
implementation 'com.squareup.picasso:picasso:2.5.2'

implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.2.0'
implementation 'androidx.lifecycle:lifecycle-livedata:2.2.0'

kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0'
def room_version = "2.2.6"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-ktx:$room_version"
testImplementation "androidx.room:room-testing:$room_version"

implementation files('libs/jxl.jar')
implementation 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.8'
implementation 'com.github.bumptech.glide:glide:3.8.0'

implementation 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.9'
implementation "com.prolificinteractive:material-calendarview:1.4.3"
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'com.github.AnyChart:AnyChart-Android:0.0.3'
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'io.reactivex:rxandroid:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.itextpdf:itext7-core:7.1.7'
implementation 'com.rmtheis:tess-two:6.0.4'
implementation files('libs/google-api-translate-java-0.98-mod2.jar')
implementation files('libs/json_simple-1.1.jar')
implementation files('libs/jtar-1.0.4.jar')
implementation files('libs/microsoft-translator-java-api-0.6-mod.jar')
implementation 'com.stepstone.stepper:material-stepper:4.3.1'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.kyanogen.signatureview:signature-view:1.0'
implementation("com.microblink:blinkid:5.9.0@aar") {
    transitive = true
}
implementation 'com.itextpdf:itext7-core:7.1.7'
implementation deps.kotlin
implementation deps.android.support.appcompat
implementation deps.android.support.constraintlayout
implementation 'com.github.yeriomin:play-store-api:0.19'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'org.jsoup:jsoup:1.11.1'
implementation 'com.google.android.play:core:1.9.0'//for new version updater
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
implementation 'com.github.jakebonk:NotifyMe:1.0.1'
implementation 'com.szagurskii:patternedtextwatcher:0.5.0'
implementation 'com.schibstedspain.android:leku:5.0.0'
testImplementation deps.test.junit
androidTestImplementation deps.test.runner
androidTestImplementation deps.test.espresso

}
repositories {
mavenCentral()
}

configurations.all {
resolutionStrategy {
    force("org.antlr:antlr4-runtime:4.5.3")
    force("org.antlr:antlr4-tool:4.5.3")
}
}

这是我的 gradle 项目:

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:4.1.2'
    classpath 'com.google.gms:google-services:4.3.4'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
    classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
 }

 allprojects {
  repositories {
    google()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
    maven {
        url 'https://maven.microblink.com' }

}
}

ext {
  supportlib_version = '27.1.1'
  appcompat_version = supportlib_version
  design_version = supportlib_version
  constraintlayout_version = '1.1.0'
  junit_version = '4.12'
  testrunner_version = '1.0.2'
  espresso_version = '3.0.2'
}

 ext.deps = [
    'kotlin' : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72",
    'android': [
            'support': [
                    'core'            : "com.android.support:support-v4:$supportlib_version",
                    'appcompat'       : 'androidx.appcompat:appcompat:1.0.0',
                    'constraintlayout': 'androidx.constraintlayout:constraintlayout:1.1.3',
                    'design'          : "com.android.support:design:$design_version"
            ]
    ],
    'test'   : [
            'junit'   : "junit:junit:$junit_version",
            'runner'  : 'androidx.test.ext:junit:1.1.1',
            'espresso': 'androidx.test.espresso:espresso-core:3.1.0'
    ]
  ]

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

 project.ext {
    blinkIdVersion = '5.9.0'
    compileSdkVersion = 28
    targetSdkVersion = 28
    buildToolsVersion = '28.0.3'
    appCompatVersion = '28.0.0'
 }

【问题讨论】:

  • 我记得我有类似的错误,我通过从 build.gradle 中删除 apply plugin: 'kotlin-kapt' 来修复它
  • 我只是尝试通过删除它并将 kapt 更改为注释处理器来尝试您的解决方案,但错误变为 unresolverd BR,当我搜索它时,由于 android studio @Andrew 的版本而必须使用 kapt

标签: android android-studio kotlin gradle kapt


【解决方案1】:
  1. 请不要从 gradle 文件中删除 apply plugin: 'kotlin-kapt'。因为它是注释处理器所必需的。

  2. 请检查您的 DAO 文件中的所有 Room 查询是否存在语法错误。您的问题中提到的错误主要发生在 Room Database Queries 不正确时。

  3. 请参考下图以获得更清晰的错误日志。这些步骤将使您更接近确切的错误。

  4. 最后,尝试使用 --stacktrace 或 --info 或 --debug 选项运行构建以获得更清晰的日志输出和完整的见解。这样您就可以找到错误的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-12
    • 2019-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2019-04-09
    • 1970-01-01
    相关资源
    最近更新 更多