0

对于使用工作人员获取设备位置的应用程序,我一直无法获得正确的依赖关系。我怀疑我在 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)

4

1 回答 1

1

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

android.enableJetifier=true
android.useAndroidX=true
于 2019-05-31T14:35:06.903 回答