更新到 WorkManager 1.0.0-alpha09 后编译错误

Compile errors after updating to WorkManager 1.0.0-alpha09

我正在尝试使用架构组件中的 WorkManager。我已将 compileSdkVersion 和 targetSdkVersion 从 27 升级到 28。gradle 同步已成功完成。但是构建时错误不断弹出。 android.support 图书馆正在使用版本 28.0.0-rc02 因为 'android.support:design'.

我尝试添加 packagingOptions 以排除 'proguard/androidx-annotations.pro'。但这没有帮助。但是这次我收到了不同的错误信息:

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

我不知道出了什么问题。

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'

编辑: 我已经在 gradle like in here

中实现了 packagingOptions
packagingOptions {
    exclude 'META-INF/proguard/androidx-annotations.pro'
}

但是这次我又得到了 5 个错误:

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

根据 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'
    }
}

编辑:您的额外错误是由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' 
}

发行说明说此错误已在 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


但是... 出于某种原因,我仍然在 1.0.0-alpha11 版本中看到此错误。

解决此问题的方法是从 work-runtime 组件中排除 listenablefuture 模块,正如@ianhanniballake 在他的回答中指出的那样。

并且排除了work-firebase组件中@Zack在评论部分指出的相同模块。


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"

如果您的项目使用 Guava v27 和最新版本的 WorkManager,一切正常。我刚刚试了一下,它修复了我的项目。

这个构建很好:

dependencies {
   implementation 'android.arch.work:work-runtime:1.0.0-beta01'
   implementation 'com.google.guava:guava:27.0.1-android'
}