Search code examples
androidbutterknifeandroid-instant-appsandroidx

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


I am trying to build an Instant App but I get an error in my base feature module:

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

I am using the following config at project level:

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/'
        }
    }
}

And this is my base feature module, which does not include an 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'

The result:

* 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\3.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.

As you can see, I am using androidX and `butterknife:9.0.0-rc2' which is the newest version that supports androidX.

The problem seems to be a dependency from butterknife that can't be Jetified

enter image description here

I can't disable jetifier as I am using androidX and SDK 28

Any help is welcome. I have also filed an issue in the Butterknife project:

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


Solution

  • Comparing your gradle setup to the instructions over at JakeWharton/butterknife...

    You seem to have unintentionally(?) added a dependency that likely causes this issue:

    base/dependencies

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

    That should only be in root/buildscript/dependencies, so remove it and try again. Otherwise, everything else looks a-ok.

    I believe Jake also hinted that @ 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.