19

I'm trying to use WorkManager from architecture components. I've upgraded the compileSdkVersion and targetSdkVersion from 27 to 28. gradle sync is successfully done. But build-time error keeps popping up. android.support libraries are using version 28.0.0-rc02 because of the 'android.support:design'.

I've tried to add packagingOptions in order to exclude 'proguard/androidx-annotations.pro'. But it didn't help. But this time I got a different error message:

Program type already present: com.google.common.util.concurrent.ListenableFuture

I could not figure out what's going wrong.

build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.apps.test"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 5
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    signingConfigs {
        release
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            resValue "bool", "enableFirebase", "true"

        }
        debug {
            minifyEnabled false
            resValue "bool", "enableFirebase", "false"

        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
//    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:design:28.0.0-rc02'
    implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'
    implementation 'com.android.support:support-v4:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:multidex:1.0.3'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation 'com.google.android.gms:play-services-auth:16.0.0'
    implementation 'com.google.firebase:firebase-firestore:17.1.0'
    implementation 'com.firebaseui:firebase-ui-firestore:4.1.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'

    //Arch
    implementation 'android.arch.core:runtime:1.1.1'
    implementation 'android.arch.core:common:1.1.1'
    implementation 'com.google.code.gson:gson:2.8.5'

    implementation "android.arch.work:work-runtime-ktx:1.0.0-alpha09"
//    implementation "android.arch.work:work-firebase:1.0.0-alpha09"
}

apply plugin: 'com.google.gms.google-services'

EDIT: I've implemented the packagingOptions in gradle like in here

packagingOptions {
    exclude 'META-INF/proguard/androidx-annotations.pro'
}

But this time I got 5 additional errors:

1:

Program type already present: com.google.common.util.concurrent.ListenableFuture
Message{kind=ERROR, text=Program type already present: com.google.common.util.concurrent.ListenableFuture, sources=[Unknown source file], tool name=Optional.of(D8)}

2:

Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...

3:

Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...

4:

Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete

5:

Caused by: com.android.tools.r8.utils.AbortException
Orcun Sevsay
  • 1,310
  • 1
  • 14
  • 44

3 Answers3

34

As per the WorkManager 1.0.0-alpha09 release notes:

Known Issue

If you run into the following issue: "More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'", please put the following in your gradle file as a temporary workaround while we fix the issue in alpha10:

android {
    packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }
}

Edit: Your additional errors are caused by this issue:

It is done on purpose: https://groups.google.com/forum/#!topic/guava-announce/Km82fZG68Sw

New release of guava will be ready soon, that will resolve that issue automatically.

For now you can exclude "com.google.guava:listenablefuture" in your gradle file:

implementation("android.arch.work:work-runtime:1.0.0-alpha09") {
    exclude group: 'com.google.guava', module: 'listenablefuture' 
}
Community
  • 1
  • 1
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Thank you @ianhanniballake. But this time I got 5 additional errors. I have updated my question above. – Orcun Sevsay Sep 23 '18 at 18:33
  • That's a totally different problem, unrelated to the first, so should probably be its own question, but I've updated my answer to that question as well. – ianhanniballake Sep 23 '18 at 19:07
  • 4
    I found the listenablefuture exclusion was needed for the firebase component too, i.e. ```implementation("android.arch.work:work-firebase:1.0.0-alpha09") { exclude group: 'com.google.guava', module: 'listenablefuture' }``` – zack Sep 28 '18 at 12:10
  • Excluding from the firebase component was also need for me. Thanks! – Keith Holliday Oct 18 '18 at 19:33
  • I am still seeing this issue on 1.0.0-alpha10, the fix is still required. – ThanksMister Nov 08 '18 at 18:27
  • i'm on 1.0.0-alpha11 and i still see the error (Error: Program type already present: com.google.common.util.concurrent.ListenableFuture) !!! – chebaby Nov 12 '18 at 13:47
  • And you'll continue to see it until you upgrade to Guava 27.0, which is when Guava starts using the same ListenableFuture dependency as WorkManager. One of your dependencies probably still relies on an older version. – ianhanniballake Nov 12 '18 at 14:45
  • I think it's not needed anymore. Use this: `final def work_version = "2.0.1" implementation "androidx.work:work-runtime-ktx:$work_version" implementation "androidx.work:work-rxjava2:$work_version"` – android developer May 20 '19 at 08:06
3

Everything works fine if you have a project with Guava v27 and the newest version of WorkManager. I just tried it out and it fixes my project.

This builds just fine:

dependencies {
   implementation 'android.arch.work:work-runtime:1.0.0-beta01'
   implementation 'com.google.guava:guava:27.0.1-android'
}
karel
  • 5,489
  • 46
  • 45
  • 50
Wisdom Ekeh
  • 256
  • 1
  • 9
  • It worked for my after adding just 1 dependency, Thanks `implementation 'com.google.guava:guava:27.0.1-android'` – dev90 May 11 '20 at 08:54
-1

The release notes say this bug was fixed in 1.0.0-alpha10:

Bug Fixes

Fixed the known issue from alpha09 regarding duplicate androidx-annotations.pro files. You may remove the workaround from the previous release notes by deleting exclude 'META-INF/proguard/androidx-annotations.pro' from your gradle file.

source


But... for some reason i still seeing this error in 1.0.0-alpha11 version.

a workaround for this, is to exclude listenablefuture module from work-runtime component as @ianhanniballake pointed in his answer.

And also exclude the same module in work-firebase component as @Zack pointed in the comments section.


build.gradle

    /*
    |--------------------------------------------------------------------------
    | WorkManager
    |--------------------------------------------------------------------------
    */

    def work_version = "1.0.0-alpha11"

    implementation("android.arch.work:work-runtime:$work_version") {
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }

    // optional - Firebase JobDispatcher support
    implementation("android.arch.work:work-firebase:$work_version") {
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }

    // optional - Test helpers
    androidTestImplementation "android.arch.work:work-testing:$work_version"
chebaby
  • 7,362
  • 50
  • 46