对于使用工作者获取设备位置的应用程序,我一直无法获得正确的依赖关系。我怀疑我在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)
答案 0 :(得分:0)
我的问题是没有包含gradle.properties文件
android.enableJetifier=true
android.useAndroidX=true