play-services-ads与appcompat发生冲突

时间:2019-09-02 16:11:11

标签: android firebase google-play-services android-appcompat androidx

当我将implementation 'com.google.android.gms:play-services-ads:18.2.0'添加到build.gradle时,Android Studio突出显示implementation 'com.android.support:appcompat-v7:28.0.0'并显示错误:

Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='versionedparcelable', myVersion='28.0.0', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.interpolator', myArtifactId='interpolator', myVersion='1.0.0', myPacking='aar', myClassifier='null'} incompatible dependencies

我的build.gradle是:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    configurations.all {
        resolutionStrategy.force 'com.android.support:appcompat-v7:28.0.0'
    }
    defaultConfig {
        applicationId "com.XXXXXX.XXXXXX"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 3
        versionName "1.1.2"
        testInstrumentationRunner "android.support.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 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'
    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'
}

1 个答案:

答案 0 :(得分:2)

您正在使用

implementation 'com.google.android.gms:play-services-ads:18.2.0'

Google Play服务已在最新版本中迁移到AndroidX。

  

使用groupId com.android.support和androidx。*的依赖项不能合并

这意味着您正在同时使用支持库和androidx库。

您可以:

  • 如下所述迁移到androidx(在您的情况下,您必须将appcompat迁移到implementation 'androidx.appcompat:appcompat:1.0.2'
  • 降级您的google play广告依赖项(但这不是真正的解决方案,因为您迟早要迁移)

您可以检查official release notes

  

警告:此版本是主要版本的更新和重大更改。   Google Play服务和Firebase的最新更新包括以下更改:

从Android支持库迁移到Jetpack(AndroidX)库。除非您在应用中进行以下更改,否则图书馆将无法工作:

  • com.android.tools.build:gradle升级到v3.2.1或更高版本。
  • compileSdkVersion升级到28或更高版本。
  • 更新您的应用以使用Jetpack(AndroidX);请按照Migrating to AndroidX中的说明进行操作。