添加 firebase 依赖项后无法构建项目

Can't build project after adding firebase dependency

我正在尝试测试 FCM,但在添加 firebase-messaging 依赖项后,应用程序无法构建。我收到了一些类似“警告:API 'variant.getMergeResources()' 已过时并已被 'variant.getMergeResourcesProvider()' 取代的警告。 它将在 2019 年底删除。”

我得到的错误是:

"Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='appcompat-v7', myVersion='28.0.0', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.slidingpanelayout', myArtifactId='slidingpanelayout', myVersion='1.0.0', myPacking='aar', myClassifier='null'}...

在线:

implementation 'com.android.support:appcompat-v7:28.0.0'

我尝试了一种解决方案,该解决方案涉及向 gradle 文件添加一些 "configurations.all" 选项,但没有奏效。我试过将 firebase 的版本更改为较早的版本,但这也不起作用。

这是我构建的模块级别 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.hfad.fcm"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        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 'com.android.support:appcompat-v7:28.0.0'
    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'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
}

apply plugin: 'com.google.gms.google-services'

错误说你不能合并 appcompat 和 androidx 库,所以把你的依赖移到 androidx ,你应该使用 androidx 库:

implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

在这里你可以看到我自己的 firebase 消息依赖项:

implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.4'

从这里查找版本 https://developer.android.com/jetpack/androidx/migrate