我已经按照教程(https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started)来设置Android上的推送通知。
我能够成功注册到通知(按照添加代码 - > 15中的要求)。
问题在于,当我进入azure通知中心并为Android平台执行“测试发送”时,“结果”结果是“从令牌提供程序获取的令牌错误”。我无法理解为什么会这样。
我无法在我的Android应用程序上设置断点并查看收到消息的位置。我创建了一个扩展FirebaseMessagingService
并覆盖public void onMessageReceived(RemoteMessage remoteMessage)
的类,但这似乎永远不会受到影响。
我无法确定从哪里,如何或为何返回此错误。
编辑:
App Gradle
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'xxx'
keyPassword 'xxx'
storeFile file('../Keys/dev-release.jks')
storePassword 'xxx'
}
}
compileSdkVersion 27
defaultConfig {
applicationId "xxx"
minSdkVersion 21
targetSdkVersion 27
versionCode 9
versionName "0.09"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
// REF: https://michiganlabs.com/2014/09/23/string-constants-generated-gradle-build-configurations/
buildTypes {
release {
/*debuggable true*/
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
buildConfigField("String", "GOOGLE_ANALYTICS_TRACKING_ID", "\"xxx\"")
}
debug {
buildConfigField("String", "GOOGLE_ANALYTICS_TRACKING_ID", "\"xxx\"")
}
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
maven { url "http://dl.bintray.com/microsoftazuremobile/SDK" }
}
}
ext.support_version = '27.1.1'
ext.lifecycle_version = '1.1.1'
ext.firebase_version = '15.0.2'
ext.glide_version = '4.7.1'
ext.smart_tab_layout_version = '1.6.1'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.github.warkiz.widget:indicatorseekbar:1.2.9'
implementation 'joda-time:joda-time:2.9.9'
implementation 'com.github.PierfrancescoSoffritti:AndroidYouTubePlayer:6.0.0'
implementation 'com.thoughtbot:expandablerecyclerview:1.4'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.mindorks:placeholderview:0.7.3'
implementation 'com.yarolegovich:discrete-scrollview:1.4.7'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.facebook.android:facebook-login:4.33.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.microsoft.azure:azure-mobile-android:3.4.0@aar'
implementation 'com.microsoft.azure:notification-hubs-android-sdk:0.4@aar'
implementation 'com.microsoft.azure:azure-notifications-handler:1.0.1@aar'
implementation 'com.google.guava:guava:25.0-android'
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.alexvasilkov:gesture-views:2.5.2'
implementation 'com.google.zxing:core:3.3.2'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0@aar'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
implementation 'com.squareup.okhttp3:okhttp:3.10.0' // 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' // REF: https://github.com/square/okhttp/issues/879
implementation 'com.squareup.mimecraft:mimecraft:1.1.1'
implementation "com.ogaclejapan.smarttablayout:library:$smart_tab_layout_version@aar"
implementation "com.ogaclejapan.smarttablayout:utils-v4:$smart_tab_layout_version@aar"
// REF: https://developers.google.com/cloud-messaging/android/android-migrate-fcm
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
implementation "com.google.firebase:firebase-messaging:17.0.0"
implementation "com.google.android.gms:play-services-analytics:16.0.0"
implementation "com.google.firebase:firebase-core:16.0.0"
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation "com.android.support:cardview-v7:$support_version"
implementation "com.android.support:animated-vector-drawable:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:customtabs:$support_version"
implementation "com.android.support:exifinterface:$support_version"
implementation "com.android.support:appcompat-v7:$support_version"
implementation "com.android.support:design:$support_version"
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:recyclerview-v7:$support_version"
implementation "com.android.support:support-v4:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version"
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
implementation "com.github.bumptech.glide:glide:$glide_version"
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Project Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 0 :(得分:1)
我发现项目文件中有多个'google-services.json'文件。删除不正确的一个并更新剩余的一个解决了问题。
答案 1 :(得分:0)
您需要在最新版本(Project grandle)中更改Google服务:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我建议您不要使用特定版本的firebase库,因此请确保您使用的是基于this link的最新版本,请检查以下实现:
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-ads:15.0.1'
implementation 'com.google.firebase:firebase-analytics:16.0.0'
implementation 'com.google.firebase:firebase-appindexing:15.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-firestore:17.0.1'
implementation 'com.google.firebase:firebase-functions:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-crash:16.0.0'
implementation 'com.google.firebase:firebase-invites:16.0.0'
implementation 'com.google.firebase:firebase-perf:16.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-config:16.0.0'