使用 Jetifier 转换 com.android.tools.build\builder.1.4\builder-3.1.4.jar' 失败。原因:重复条目:module-info.class

Failed to transform com.android.tools.build\builder\3.1.4\builder-3.1.4.jar' usingJetifier. Reason: duplicate entry: module-info.class

我正在尝试构建即时应用程序,但我在基本功能模块中遇到错误:

 Failed to transform 'C:\...\.gradle\caches\modules-2\files-2.1\com.android.tools.build\builder.1.4\...\builder-3.1.4.jar' using
 Jetifier. Reason: duplicate entry: module-info.class. 

我在项目级别使用以下配置:

buildscript {
    ext.kotlin_version = '1.3.10'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
           url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.jakewharton:butterknife-gradle-plugin:9.0.0-rc2'

    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
           url 'https://maven.google.com/'
        }
    }
}

这是我的基本功能模块,不包含 applicationId

apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.jakewharton.butterknife'

apply plugin: 'com.google.cloud.tools.endpoints-framework-client'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        // V2: Add the new Endpoints Framework plugin dependencies
        classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
    }
}

android {
    compileSdkVersion 28

    baseFeature true

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 2302
        versionName "2.3.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        setProperty("archivesBaseName", "phone-release-$versionCode")

    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

ext {
    butterknifeVersion = "9.0.0-rc2"
}

dependencies {
    application project(':installed')
    kapt "com.jakewharton:butterknife-compiler:${butterknifeVersion}"
    debugImplementation 'com.facebook.stetho:stetho:1.5.0'
    endpointsServer project(path: ':api', configuration: 'endpoints')
    implementation(project(':core'))

    implementation 'com.annimon:stream:1.2.1'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation('com.google.api-client:google-api-client:1.23.0') {
        exclude module: 'httpclient'
    }
    implementation('com.google.api-client:google-api-client-android:1.23.0') {
        exclude module: 'httpclient'
    }

    implementation "com.google.android.gms:play-services-maps:16.0.0"
    implementation "com.google.android.gms:play-services-analytics:16.0.5"
    implementation "com.google.android.gms:play-services-location:16.0.0"
    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation "com.google.firebase:firebase-ads-lite:17.1.1"
    implementation "com.google.firebase:firebase-messaging:17.3.4"
    implementation "com.google.firebase:firebase-config:16.1.0"
    implementation 'com.google.code.gson:gson:2.8.5'

    implementation 'com.google.maps.android:android-maps-utils:0.5'

    implementation "com.jakewharton:butterknife:${butterknifeVersion}"
    implementation "com.jakewharton:butterknife-gradle-plugin:${butterknifeVersion}"
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.2.2'
    implementation group: 'io.reactivex.rxjava2', name: 'rxandroid', version: '2.0.2'

}

sourceCompatibility = "1.8"
targetCompatibility = "1.8"

apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android-extensions'

结果:

* What went wrong:
Execution failed for task ':base:compileDebugKotlin'.
> Could not resolve all artifacts for configuration ':base:debugCompileClasspath'.
   > Failed to transform file 'builder-3.1.4.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
      > Failed to transform 'C:\...\.gradle\caches\modules-2\files-2.1\com.android.tools.build\builder.1.4\afbcd4b7002c61fe898b1b4c50ed9e62386125d8\
builder-3.1.4.jar' using Jetifier. Reason: duplicate entry: module-info.class. (Run with --stacktrace for more details.) To disable Jetifier, set android.enable
Jetifier=false in your gradle.properties file.

如您所见,我使用的是 androidX 和 `butterknife:9.0.0-rc2',这是支持 androidX 的最新版本。

问题似乎是来自 butterknife 的依赖项无法被 Jetified

我无法禁用 jetifier,因为我使用的是 androidX 和 SDK 28

欢迎任何帮助。我也在 Butterknife 项目中提出了一个问题:

https://github.com/JakeWharton/butterknife/issues/1414

将您的 gradle 设置与 JakeWharton/butterknife 中的说明进行比较...

您似乎无意中(?)添加了可能导致此问题的依赖项:

base/dependencies

  • implementation "com.jakewharton:butterknife-gradle-plugin:${butterknifeVersion}"

那只应该在 root/buildscript/dependencies 中,所以请将其删除并重试。否则,其他一切看起来都还不错。

我相信杰克也暗示过@JakeWharton/butterknife/issues/1414#issuecomment-443880715

The Gradle plugin should be added to the buildscript classpath and not the app's implementation config. Please see the readme for a copy/paste example.