如何为WorkManager和LocationServices获取正确的依赖项



我一直无法为使用worker获取设备位置的应用程序获取正确的依赖项。我怀疑我在 androidx 中使用了错误的位置服务,但我没有找到其他任何东西。这是我的build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.exelor.laytrax"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
    implementation 'androidx.work:work-runtime:2.1.0-alpha02'
    implementation 'com.google.android.material:material:1.1.0-alpha06'
    implementation ('com.google.android.gms:play-services-location:16.0.0') {
        exclude group: 'com.android.support'
    }
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

我排除了com.android.support以避免构建异常,例如

Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.1.0-beta01) and classes.jar (com.android.support:support-compat:26.1.0)

在运行时在worker doWork((:

fusedLocationClient = LocationServices.getFusedLocationProviderClient(context.applicationContext)

引发此异常:

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArraySet;
        at com.google.android.gms.common.api.internal.GoogleApiManager.<init>(Unknown Source:29)

我的问题是没有包含 gradle.properties 的文件

android.enableJetifier=true
android.useAndroidX=true

最新更新