插件冲突错误:Google plus和Push插件

时间:2018-05-22 10:31:05

标签: android cordova phonegap-plugins phonegap-build phonegap

我需要使用google plus和推送通知,但 Phonegap Build会出错

  

请通过更新版本来修复版本冲突   google-services插件(有关最新版本的信息是   可在bintray.com/android/...获取或更新版本   com.google.android.gms到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>

config.xml:

    <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" />

1 个答案:

答案 0 :(得分:2)

播放服务库<let yourService: YourService; beforeEach(() => { fixture = TestBed.createComponent(YourComponent); component = fixture.componentInstance; store = TestBed.get(YourService); fixture.detectChanges(); }); it('should call the right funtion', () => { spyOn(yourService, 'yourMethod');// or spyOn(component, 'yourMethod'); const fakeEvent = { preventDefault: () => console.log('preventDefault') }; fixture.debugElement.query(By.css('form')).triggerEventHandler('submit', fakeEvent); expect(yourService.yourMethod).toHaveBeenCalledWith( //your logic here ); }); )的

cordova-plugin-googleplus currently pins v11.8.0

Firebase库的

com.google.android.gms currently pins v11.6.2依次固定播放服务库的v11.6.2。

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

phonegap-plugin-push现在depends cordova-support-google-services pull in v3.2.0 of the Google Services plugin cordova-android-play-services-gradle-release也间接引用了Play服务库。

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

如果您在本地构建,可以使用doesn't support the execution of hooks scripts执行此操作:

phonegap-plugin-push

但是,您正在构建cordova plugin add cordova-android-play-services-gradle-release --variable PLAY_SERVICES_VERSION=11.6.2 所依赖的{{3}} Phonegap Build。

因此,您最好的解决方案可能是cordova-android-play-services-gradle-release分叉并在cordova-plugin-googleplus中将Play服务版本设置为11.6.2,然后在您的构建中使用该分支。