android - 插件冲突错误: Google plus and Push plugin

标签 android cordova phonegap-plugins phonegap-build phonegap

我需要同时使用 google plus 和推送通知,但是 Phonegap Build 出错:

Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at bintray.com/android/…) or updating the version of com.google.android.gms to 11.6.2.

index.html :

<!DOCTYPE html>
<html>
  <head>
    <title>Device Ready Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" src="push.js"></script> 


    <script> 

    // Wait for device API libraries to load
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    //
    function onDeviceReady() {
        // Now safe to use device APIs
        var push = PushNotification.init({
            "android": {
              "senderID": "xxxxxxxxxx"
            },
        });


    push.on('registration', function(data) {
        alert('registration event: ' + data.registrationId);
        console.log('registration event: ' + data.registrationId);

        var oldRegId = localStorage.getItem('registrationId');
        if (oldRegId !== data.registrationId) {
        // Save new registration ID
        localStorage.setItem('registrationId', data.registrationId);
        // Post registrationId to your app server as the value has changed
     }

    var parentElement = document.getElementById('registration');
    var listeningElement = parentElement.querySelector('.waiting');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');
  });
}

    </script>
  </head>
  <body onload="onLoad()">
  </body>
</html>

配置文件:

    <widget id="com.phonegap.notificationtest1" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
        <name>notificationtest1</name>
        <description>
         notificationtest1
        </description>
        <author email="support@phonegap.com" href="http://phonegap.com">
            sqlchild
        </author> 


            <preference name="android-minSdkVersion" value="17" /> 

            <preference name='phonegap-version' value='cli-8.0.0' />

            <preference name='pgb-builder-version' value='2' />



    <plugin name="phonegap-plugin-push" spec="2.1.3">   
            <param name="SENDER_ID" value="xxxxxxxxxxxx" />
    </plugin> 


        <plugin name="cordova-plugin-googleplus" source="npm" spec="5.3.0"></plugin>  


        <platform name="android">   

            <resource-file src="app/google-services.json" target="app/google-services.json" />  

        </platform>      


        <content src="index.html" />

最佳答案

cordova-plugin-googleplus currently pins v11.8.0 Play 服务库 (com.google.android.gms)。

phonegap-plugin-push currently pins v11.6.2 Firebase 库的版本,它又固定了 Play 服务库的 v11.6.2。

因此,Play 服务库的版本冲突导致了您的构建错误。

phonegap-plugin-push 现在也是 dependscordova-support-google-servicespull in v3.2.0 of the Google Services plugin ,它也间接引用了 Play 服务库。

TL;DR:您需要让 cordova-plugin-googleplus 指定与 phonegap-plugin-push 相同版本的 Play 服务库。

如果您在本地构建,您可以使用 cordova-android-play-services-gradle-release这样做:

cordova plugin add cordova-android-play-services-gradle-release  --variable PLAY_SERVICES_VERSION=11.6.2

但是,您正在使用 Phonegap Build 构建 doesn't support the execution of hooks scripts cordova-android-play-services-gradle-release 依赖于它。

所以你最好的解决方案可能是 fork cordova-plugin-googleplus 并在 plugin.xml 中将 Play Services 版本设置为 11.6.2 >,然后在您的构建中使用该分支。

关于android - 插件冲突错误: Google plus and Push plugin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50465483/

相关文章:

ios - 推送通知已发送到苹果 apns 服务器,但设备未收到任何信息

android - 为什么在 Android GridView 中滚动时项目会改变顺序?

java - 为什么在关闭手机时进入 OnCreate()?

c# - Xamarin.Android - 如何实现通用图像加载器库中使用的回调

javascript - 条码扫描仪Phonegap插件;无法将结果保存到全局变量或保存到隐藏字段

javascript - Apache Cordova 无法加载插件

android - 自定义形状的 TextView ,Android

ios - 将扫描仪 UI 修改为矩形纵向 vs 320x480

android - Cordova iOS 不从地理链接打开 map

javascript - 如何为 cordova 应用程序创建一个单独的目录并在其中存储数据?