我想用Firebase Cloud Messenging服务实施推送通知。我添加了:
ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated
npm install @ionic-native/fcm
在app.component.ts
中:
import { FCM } from '@ionic-native/fcm/ngx';
// ...
constructor(private fcm: FCM)
// ...
this.fcm.getToken().then(token => {
console.log('Token :', token);
});
这使我在台式机中出现错误,因为Cordova不可用,没关系。
但是,当我想像往常一样在android上进行测试时,我会做出:
ionic cordova run android --device
这给了我一个错误:
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\<username>\Documents\weezchat_ionic\platforms\android\cordova-plugin-fcm-with-dependecy-updated\billingtests-FCMPlugin.gradle' line: 21
* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
> For input string: "+"
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
[ERROR] An error occurred while running subprocess cordova.
cordova run android --device exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
我正在与:
Ionic:
ionic (Ionic CLI) : 4.12.0 (C:\Users\username\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.1.1
@angular-devkit/build-angular : 0.13.6
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.6
@ionic/angular-toolkit : 1.4.0
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 8 other plugins)
System:
Android SDK Tools : 26.1.1 (C:\Users\username\AppData\Local\Android\Sdk)
NodeJS : v10.15.3 (C:\Program Files\nodejs\node.exe)
npm : 6.9.0
OS : Windows 10
这是\ platforms \ android \ cordova-plugin-fcm-with-dependency-updated \ billingtests-FCMPlugin.gradle内容:
buildscript {
repositories {
mavenCentral()
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.+'
classpath 'com.google.gms:google-services:3.1.+'
}
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'com.google.firebase:firebase-core:10.+'
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
答案 0 :(得分:1)
我遇到了完全相同的问题,终于能够通过一些猜测来解决此链接中的信息: cordova-android-play-services-gradle-release
这涉及添加一个特殊的插件来尝试设置所需的播放服务版本号。这个特殊的设置对我有用:
cordova plugin add cordova-android-play-services-gradle-release --variable PLAY_SERVICES_VERSION=16+
基本上,这似乎只是在 config.xml 中自动添加版本号:
<plugin name="cordova-android-play-services-gradle-release" spec="^2.1.0">
<variable name="PLAY_SERVICES_VERSION" value="16+" />
</plugin>
也许您的情况需要一个不同的版本号,或者可能会因为使用Ionic 4并尝试添加推插件而有所不同。无论哪种方式,我都相信答案就在这种情况下。
*注意:这与插件 cordova-plugin-firebase
结合使用答案 1 :(得分:0)
我遇到了同样的问题,这是因为我错过了 com.google.gms:google-services
依赖项。我这样做是因为我在 Flutter 中重新生成了 Android 文件:
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.8'
}
请务必按照 set up documentation 中的说明进行操作。