1

I am working on a dynamic feature module for the first time. I am getting issues in minify gradle task. It says ListenableFuture file exists in base.jar and alt_acco.jar

below is my project configuration:

mobile.gradle

dynamicFeatures = [':alt_acco']

alt_acco.gradle. feature module

apply plugin: 'com.android.dynamic-feature'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

lintOptions {
    checkReleaseBuilds false
    // Or, if you prefer, you can continue to check for errors in release builds,
    // but continue the build even when errors are found:
    abortOnError false
    tasks.lint.enabled = false
}

defaultConfig {
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    consumerProguardFiles 'consumer-rules.pro'
    missingDimensionStrategy 'react-native-camera', 'general'
}

compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
    incremental true
}

buildTypes {
    release {
    }

    releaseStaging {
        matchingFallbacks = ['release']
    }

    debug {
    }
}

productFlavors {
    flavorDimensions "type"
    standard {
        dimension "type"
        buildConfigField 'Boolean', 'Automation', 'false'
    }
    standardBasicOptimized {
        dimension "type"
        buildConfigField 'Boolean', 'Automation', 'false'
    }
    standard_charles {
        dimension "type"
        buildConfigField 'Boolean', 'Automation', 'false'
    }
    automation_charles {
        dimension "type"
        buildConfigField 'Boolean', 'Automation', 'true'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

dataBinding {
    enabled = true
}
}

dependencies {
// Import the Firebase BoM (see: https://firebase.google.com/docs/android/learn-more#bom)
implementation platform('com.google.firebase:firebase-bom:28.2.1')

// Firestore (Java)
implementation 'com.google.firebase:firebase-firestore'

// Firestore (Kotlin)
implementation 'com.google.firebase:firebase-firestore-ktx'

// Google Play services
implementation project(path: ':mobile')
}

settings.gradle

include ':alt_acco'

I am making a release build and the error I am getting is as follows:

Task :mobile:minifyStandardBasicOptimizedReleaseWithR8
/root/.gradle/caches/transforms-3/1169397e4788b932b8c86a71183af227/transformed/jetified-time4j-android-4.2-2018i/proguard.txt:1:1-27: R8: Ignoring option: -useuniqueclassmembernames
/opt/jenkins/workspace/APP-Android-Verify/mobile/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/base.jar: R8: Type com.google.common.util.concurrent.ListenableFuture is defined multiple times: /opt/jenkins/workspace/APP-Android-Verify/mobile/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/base.jar:com/google/common/util/concurrent/ListenableFuture.class, /opt/jenkins/workspace/APP-Android-Verify/alt_acco/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/feature-alt_acco.jar:com/google/common/util/concurrent/ListenableFuture.class

> Task :mobile:minifyStandardBasicOptimizedReleaseWithR8 FAILED
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mobile:minifyStandardBasicOptimizedReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /opt/jenkins/workspace/APP-Android-Verify/mobile/build/intermediates/module_and_runtime_deps_classes/standardBasicOptimizedRelease/base.jar:com/google/common/util/concurrent/ListenableFuture.class

Help will be really appreciated.

2 Answers2

0

Hey I had same issue because we had gradle cache enabled, I got it working by adding ./gradlew bundleRelease --no-build-cache, hope it helps.

2f world
  • 13
  • 1
  • 3
0

What the error says is you have the class com/google/common/util/concurrent/ListenableFuture that appears twice, once in your base module and once in your :alt_acco module.

Your app needs to depend on this class only once. To make sure it works in both cases (1) when only the base module is installed and (2) when the base module and the :alt_acco module are installed, you should removed the class from the :alt_acco module.

To do this, you can use Gradle exclude directive. The way it works is you first locate the dependency that depends on the library that has the class com/google/common/util/concurrent/ListenableFuture. For this, you use Gradle and run the command ./gradlew alt_acco:dependencies. For alternatives, look at this good answer. You should get a dependency tree and you should now locate the line that has a group starting like com.google.common.util.... You find the artifact and you exclude it.

You can exclude a dependent artifact by specifying its group and module, on the relevant line of the alt_acco's build.gradle file:

implementation('direct-dependency-group:direct-dependency-module') {
    exclude group: 'duplicate-dependency-group', module: 'duplicate-dependency-module'
}

The direct dependency is one in your alt_acco module, and the duplicate dependency will be the one containing the duplicate class com/google/common/util/concurrent/ListenableFuture.

Vince
  • 1,570
  • 3
  • 27
  • 48