如何解决cordova-plugin-googleplus与cordova-plugin-firebasex共存冲突?
问题
我有一个Cordova应用,用cordova-plugin-googleplus实现谷歌登录,cordova-plugin-firebasex实现推送通知。单独使用任意一个插件都能正常运行,但同时引入两个插件时出现问题,推测是插件依赖的Google Play Service版本冲突导致的,但找不到解决办法。
我先安装了cordova-plugin-firebasex,命令如下:
cordova plugin add cordova-plugin-firebasex \ --variable ANDROID_PLAY_SERVICES_AUTH_VERSION=15.0.1
应用能正常编译运行。但安装cordova-plugin-googleplus时:
$ cordova plugin add cordova-plugin-googleplus \ --variable REVERSED_CLIENT_ID=com.myapp.whatever \ --variable WEB_APPLICATION_CLIENT_ID=whatever.myapp.com \ --variable PLAY_SERVICES_VERSION=15.0.1 Installing "cordova-plugin-googleplus" for ios cordova-plugin-googleplus depends on GoogleSignIn, which may conflict with another plugin. GoogleSignIn@6.2.1 is already installed and was not overwritten.
cordova-plugin-googleplus文档说明:
To set up Google Play Services version, you can use PLAY_SERVICES_VERSION parameter (with 11.8.0 value by default). It is useful in order to avoid conflicts with another plugins which use any other different version of Google Play Service, because they MUST be the same version.
我已经尝试结合cordova-plugin-firebasex文档中的ANDROID_PLAY_SERVICES_AUTH_VERSION设置,但没有效果,请问该如何解决这两个插件的版本冲突问题?
解决方法
1. 统一iOS端GoogleSignIn版本
提示里的冲突是iOS端GoogleSignIn版本导致的,Android端你已经统一为15.0.1,现在需要指定iOS端的GoogleSignIn版本,覆盖已安装的包:
cordova plugin add cordova-plugin-googleplus \ --variable REVERSED_CLIENT_ID=com.myapp.whatever \ --variable WEB_APPLICATION_CLIENT_ID=whatever.myapp.com \ --variable PLAY_SERVICES_VERSION=15.0.1 \ --variable GOOGLE_SIGN_IN_VERSION=6.2.1
如果此版本仍冲突,可尝试兼容性较好的旧版本,比如5.0.2:
cordova plugin add cordova-plugin-googleplus \ --variable REVERSED_CLIENT_ID=com.myapp.whatever \ --variable WEB_APPLICATION_CLIENT_ID=whatever.myapp.com \ --variable PLAY_SERVICES_VERSION=15.0.1 \ --variable GOOGLE_SIGN_IN_VERSION=5.0.2
2. 调整插件安装顺序
先安装cordova-plugin-googleplus并指定版本,再安装cordova-plugin-firebasex匹配对应auth版本,避免后安装的插件覆盖依赖:
# 先安装googleplus cordova plugin add cordova-plugin-googleplus \ --variable REVERSED_CLIENT_ID=com.myapp.whatever \ --variable WEB_APPLICATION_CLIENT_ID=whatever.myapp.com \ --variable PLAY_SERVICES_VERSION=15.0.1 \ --variable GOOGLE_SIGN_IN_VERSION=6.2.1 # 再安装firebasex cordova plugin add cordova-plugin-firebasex \ --variable ANDROID_PLAY_SERVICES_AUTH_VERSION=15.0.1
3. 强制清理后重新安装
如果残留缓存导致冲突,先卸载所有相关插件并清理缓存,再重新安装:
# 卸载插件 cordova plugin remove cordova-plugin-firebasex cordova-plugin-googleplus # 清理Cordova缓存 cordova clean # 重新按顺序安装插件 cordova plugin add cordova-plugin-googleplus \ --variable REVERSED_CLIENT_ID=com.myapp.whatever \ --variable WEB_APPLICATION_CLIENT_ID=whatever.myapp.com \ --variable PLAY_SERVICES_VERSION=15.0.1 \ --variable GOOGLE_SIGN_IN_VERSION=6.2.1 cordova plugin add cordova-plugin-firebasex \ --variable ANDROID_PLAY_SERVICES_AUTH_VERSION=15.0.1
4. 全局配置依赖版本
直接在config.xml中添加全局偏好设置,强制所有插件使用统一版本:
<platform name="android"> <preference name="PLAY_SERVICES_VERSION" value="15.0.1" /> </platform> <platform name="ios"> <preference name="GOOGLE_SIGN_IN_VERSION" value="6.2.1" /> </platform>
添加后重新构建项目:
cordova build android cordova build ios
内容的提问来源于stack exchange,提问作者d512

