我正在使用Firebase云消息传递来显示推送通知。一段时间前,在同一个项目上一切正常。现在,当我尝试从Firebase检索令牌时遇到Token retrieval failed:SERVICE_NOT_AVAILABLE
错误。我已经看到了一些与Facebook SDK和模拟器连接的堆栈溢出解决方案。我正在多个真实设备上进行测试,但这些解决方案均无效。
这是我的应用程序等级
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':materialrangebar')
api 'com.squareup.retrofit2:retrofit:2.5.0'
api 'com.squareup.retrofit2:converter-gson:2.3.0'
api 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
implementation 'com.facebook.fresco:fresco:1.12.0'
implementation "com.facebook.fresco:imagepipeline-okhttp3:1.5.0"
implementation 'com.github.stfalcon:frescoimageviewer:0.5.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.maps.android:android-maps-utils:0.5'
}
apply plugin: 'com.google.gms.google-services'
这就是我试图获取令牌的方式
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete( Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.e(TAG, "getInstanceId failed", task.getException());
return;
} else {
requestDeviceRegistration(task.getResult().getToken());
Log.e(TAG, task.getResult().getToken());
}
}
});
答案 0 :(得分:0)
我将按照以下步骤操作add Firebase to your project.,确保您的google-services.json
是正确的,并且您已设置了包含build.gradle
的根级别classpath 'com.google.gms:google-services:4.3.0'