FCM 插件和 Google Plus 冲突
Posted
技术标签:
【中文标题】FCM 插件和 Google Plus 冲突【英文标题】:FCMPluging and GooglePlus conflict 【发布时间】:2018-12-18 22:29:51 【问题描述】:我正在尝试在Ionic2
Type Script
android
应用程序中使用几个插件
Push Notification:
ionic cordova plugin add phonegap-plugin-push --variable SENDER_ID=mySenderId
npm install --save @ionic-native/push
GooglePlus 用于认证:
cordova plugin add cordova-plugin-googleplus --variable REVERSED_CLIENT_ID=myReversedClientId
npm install --save @ionic-native/google-plus
和FCM 将Push Notification 和FCMPlugin 发送到特定设备:
ionic cordova plugin add cordova-plugin-fcm
npm install --save @ionic-native/fcm
在我添加最后一个安装 fcm 之前,我的 project.properties
是:
target=android-26
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.system.library.2=com.android.support:support-v4:25.+
cordova.system.library.3=com.android.support:appcompat-v7:25.+
cordova.system.library.4=com.android.support:support-v13:26.+
cordova.system.library.5=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.6=com.google.firebase:firebase-messaging:11.6.2
cordova.gradle.include.1=phonegap-plugin-push/myapp-push.gradle
cordova.system.library.7=com.google.android.gms:play-services-auth:11.6.2
cordova.system.library.8=com.google.android.gms:play-services-identity:11.6.2
和config.xml
:
...
<plugin name="phonegap-plugin-push" spec="^2.1.3">
<variable name="SENDER_ID" value=" mySenderId " />
<variable name="FCM_VERSION" value="11.6.2" />
</plugin>
<plugin name="cordova-plugin-googleplus" spec="^5.3.0">
<variable name="REVERSED_CLIENT_ID" value=" myReversedClientId " />
</plugin>
<engine name="android" spec="7.0.0" />
</widget>
安装fcm
后是:
target=android-26
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.system.library.2=com.android.support:support-v4:25.+
cordova.system.library.3=com.android.support:appcompat-v7:25.+
cordova.system.library.4=com.android.support:support-v13:26.+
cordova.system.library.5=me.leolin:ShortcutBadger:1.1.17@aar
cordova.system.library.6=com.google.firebase:firebase-messaging:11.6.2
cordova.gradle.include.1=phonegap-plugin-push/myapp-push.gradle
cordova.system.library.7=com.google.android.gms:play-services-auth:11.6.2
cordova.system.library.8=com.google.android.gms:play-services-identity:11.6.2
cordova.system.library.9=com.google.firebase:firebase-core:+
cordova.system.library.10=com.google.firebase:firebase-messaging:+
cordova.gradle.include.2=cordova-plugin-fcm/myapp-FCMPlugin.gradle
和config.xml
:
...
<plugin name="phonegap-plugin-push" spec="^2.1.3">
<variable name="SENDER_ID" value=" mySenderId " />
<variable name="FCM_VERSION" value="11.6.2" />
</plugin>
<plugin name="cordova-plugin-googleplus" spec="^5.3.0">
<variable name="REVERSED_CLIENT_ID" value=" myReversedClientId " />
</plugin>
<plugin name="cordova-plugin-fcm" spec="^2.1.2" />
<engine name="android" spec="7.0.0" />
</widget>
当我开始构建项目时,我遇到了几个错误,已解决如下:
ERROR 1(无效数据,块必须是字符串或缓冲区,而不是对象):
在plugins/cordova-plugin-fcm/scripts/fcm_config_files_process.js
:
改变:
var strings = fs.readFileSync("platforms/android/res/values/strings.xml").toString();
到:
var strings = fs.readFileSync("platforms/android/app/src/main/res/values/strings.xml").toString();
改变:
fs.writeFileSync("platforms/android/res/values/strings.xml", strings);
到:
fs.writeFileSync("platforms/android/app/src/main/res/values/strings.xml", strings);
错误 2(任务 ':app:processDebugGoogleServices' 执行失败。):
在plugins/cordova-plugin-fcm/src/android/FCMPlugin.gradle
和platforms/android/cordova-plugin-fcm/myapp-FCMPlugin.gradle
中:
buildscript
repositories
jcenter()
mavenLocal()
dependencies
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.0.0'
改变这个:
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
到这里:
ext.postBuildExtras =
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
编辑ionic cordova build
后,android
应用程序没有错误,但带有身份验证和获取用户数据的GooglePlus
按钮停止工作:
googleRegistration()
this.googlePlus.login(
'webClientId': 'myClientId',
'offLine': true
)
.then(res =>
firebase.auth().signInWithCredential(firebase.auth.GoogleAuthProvider.credential(res.idToken))
.then(suc =>
alert("LOGIN SUCCESSFUL")
).catch(ns =>
"LOGIN NOT SUCCESSFUL"
)
this.displayName = res.displayName;
this.email = res.email;
this.userId = res.userId;
...
)
.catch(err => console.error(err));
不知道怎么弄,建议很有帮助
【问题讨论】:
【参考方案1】:试试@michalakjan 的解决方案 (来自https://github.com/EddyVerbruggen/cordova-plugin-googleplus/issues/487)
ionic cordova plugin add cordova-plugin-platform-replace
-- config.xml
<platform name="android">
<replace-string file="project.properties" find="com.google.android.gms:play-services-auth:11.8.0" replace="com.google.android.gms:play-services-auth:+" />
<replace-string file="project.properties" find="com.google.android.gms:play-services-identity:11.8.0" replace="com.google.android.gms:play-services-identity:+" />
【讨论】:
以上是关于FCM 插件和 Google Plus 冲突的主要内容,如果未能解决你的问题,请参考以下文章
Google Plus PHP API 与其他 API 文件冲突