如何修复无法使用 Jetifier 转换 kotlin-android-extensions-1.3.71.jar' 错误?

Dee*_*ohn 4 android kotlin androidx

任务“:app:mergeDebugJavaResource”执行失败。

无法解析配置“:app:debugRuntimeClasspath”的所有文件。无法转换工件“kotlin-android-extensions.jar (org.jetbrains.kotlin:kotlin-android-extensions:1.3.71)”以匹配属性 {artifactType=android-java-res, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}。JetifyTransform 执行失败:C:\Users\user.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-android-extensions\1.3.71\ea43e0e563e1915ea845a482fd6f31a948386ab9\kotlin-android-extensions-1.3。 71.jar。无法转换 'C:\Users\user.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-android-extensions\1.3.71\ea43e0e563e1915ea845a482fd6f31a948386ab9\kotlin-android-extensions-1.3.71 .jar' 使用 Jetifier。原因:给定的工件包含带有包引用“android.support.v4”的字符串文字,无法安全地重写。使用反射的库(例如注释处理器)需要手动更新以添加对 androidx 的支持。

应用程序构建.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.appname"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    //to avoid retrofit client error
    compileOptions {
        targetCompatibility = JavaVersion.VERSION_1_8
        sourceCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }
}
androidExtensions {
    experimental = true
}

dependencies {
    ext.kotlin_version = '1.3.71'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    implementation 'com.google.firebase:firebase-auth:19.1.0'
    def lifecycle_version = '2.2.0'
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    // Optional : Kotlin extension (https://d.android.com/kotlin/ktx)
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation 'androidx.core:core-ktx:1.2.0'
    def appcompat_version = "1.1.0"

    implementation "androidx.appcompat:appcompat:$appcompat_version"
    // For loading and tinting drawables on older versions of the platform
    implementation "androidx.appcompat:appcompat-resources:$appcompat_version"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.viewpager2:viewpager2:1.0.0"
    implementation "androidx.legacy:legacy-support-v4:1.0.0"
    implementation 'com.google.android.gms:play-services-maps:17.0.0'

    //GIF
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'

    ext {
        retrofit_version = '2.8.1'
    }
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'io.reactivex.rxjava2:rxjava:2.2.19'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation("io.reactivex.rxjava2:rxkotlin:2.4.0")
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    // Skip this if you don't want to use integration libraries or configure Glide.
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'

    def room_version = "2.2.5"

    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor

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

    // optional - RxJava support for Room
    implementation "androidx.room:room-rxjava2:$room_version"
}
repositories {
    mavenCentral()
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

gradle.properties

org.gradle.jvmargs=-Xmx1536m
org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official
kotlin.caching.enabled=false
Run Code Online (Sandbox Code Playgroud)

项目 gradle.build

buildscript {
    ext.kotlin_version = '1.3.71'
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
        classpath 'com.google.gms:google-services:4.3.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

mag*_*non 8

就我而言,删除该行

    implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Run Code Online (Sandbox Code Playgroud)

从应用程序 build.gradle 解决了这个问题。“Kotlin Android 扩展”功能似乎仅通过classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"在项目 build.gradle 和apply plugin: 'kotlin-android-extensions'.

以下是一个相关问题(但还没有答案):

无法转换工件“kotlin-android-extensions.jar”