OneSignal 导致 Google Play 服务版本发生变化

OneSignal causing Google Play Services version to change

我正在尝试将 OneSignal 集成到我的项目中,但它导致 Google Play 服务出错。

这是我的 build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

dependencies {
    ...

    implementation "com.google.firebase:firebase-core:16.0.1"
    implementation "com.google.firebase:firebase-messaging:17.3.0"

    implementation "com.google.android.gms:play-services-plus:15.0.1"
    implementation "com.google.android.gms:play-services-auth:15.0.1"
    implementation "com.google.android.gms:play-services-location:15.0.1"
    implementation "com.google.android.gms:play-services-maps:15.0.1"
    implementation "com.google.android.gms:play-services-places:15.0.1"
    implementation "com.google.android.gms:play-services-wallet:15.0.1"

    ...
}

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

现在,我添加了 OneSignal。

buildscript {
    ...

    dependencies {
        ...

        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.8.1'

        ...
    }
}

这是我更新的 build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

dependencies {
    ...

    implementation "com.google.firebase:firebase-core:16.0.1"
    implementation "com.google.firebase:firebase-messaging:17.3.0"

    implementation "com.google.android.gms:play-services-plus:15.0.1"
    implementation "com.google.android.gms:play-services-auth:15.0.1"
    implementation "com.google.android.gms:play-services-location:15.0.1"
    implementation "com.google.android.gms:play-services-maps:15.0.1"
    implementation "com.google.android.gms:play-services-places:15.0.1"
    implementation "com.google.android.gms:play-services-wallet:15.0.1"

    ...

    implementation 'com.onesignal:OneSignal:3.9.1'

    ...
}

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

现在,与此同步会导致错误:

Failed to resolve: com.google.firebase:firebase-core:17.3.0
...

Failed to resolve: com.google.android.gms:play-services-plus:17.3.0
...

Failed to resolve: com.google.android.gms:play-services-auth:17.3.0
...

出于某种原因,添加 OneSignal 会导致 Google Play 服务升级到我的 firebase-messaging 版本 ( 17.3.0 )

有什么办法可以解决这个问题吗?谢谢。

您还需要在顶级 build.gradle 中使用最新版本的 Google Play 服务插件:

classpath 'com.google.gms:google-services:4.1.0'

尝试添加 google 存储库

repositories {
    jcenter()
    google()
    ...
}

One Signal 在内部处理 firebase 的依赖性。为什么在您的应用程序中使用 firebase 依赖项 gradle?删除它们并重建。

删除它们

implementation "com.google.firebase:firebase-core:16.0.1"
implementation "com.google.firebase:firebase-messaging:17.3.0"

尝试使用版本范围并在项目级别替换它 gradle

dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
    }

这在应用级别 gradle 依赖项

implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'

此外,你错过了 oneSignal ID(来自你当前发布的想法 gradle) 也加上那个 check here

一旦你完成了 syn do clean and rebuild project 选项

您需要像这样使用最新版本的 firebase 依赖项,

 com.google.firebase:firebase-core:16.0.3
com.google.firebase:firebase-messaging:17.1.0
com.google.firebase:firebase-crash:16.0.1
com.google.firebase:firebase-config:16.0.0
com.google.firebase:firebase-perf:16.0.0

试试这个。