我还是Android的新手,我想创建一个具有导航抽屉并获取位置更新的应用。用导航抽屉创建一个项目后,我的依赖关系如下:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:+'
implementation 'com.android.support:support-v4:+'
implementation 'com.android.support:design:+'
implementation 'com.android.support.constraint:constraint-layout:1.1.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'}
然后,我完成本教程:https://developer.android.com/training/location/receive-location-updates 它需要这些依赖项:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
}
但是当我将它们放在一起时,它们会发生冲突,并且我找不到解决它们的方法。
我尝试添加排除项,然后迁移到androidx,但这无济于事。我要么遇到这样的冲突:
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
或者一些冲突的软件包(如果我尝试修复清单):
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:26.1.0)
有没有一种方法可以解决此问题,以便UI和Location都能正常工作?
答案 0 :(得分:1)
您必须更改
implementation 'com.google.android.gms:play-services-location:16.0.0'
此版本使用支持库,您不能同时使用androidx和支持库。
使用迁移到androidx的play-services-location
中的updated version。
implementation 'com.google.android.gms:play-services-location:17.0.0'