我一直在尝试将Firebase云消息传递添加到我的应用程序中,但无法通过此问题。每当我在android>app>build.gradle
中包含Firebase消息传递时,我的应用程序就会启动,但立即关闭,然后挂在“正在安装build \ app \ outputs \ apk \ app.apk” :
implementation 'com.google.firebase:firebase-messaging:20.1.6'
android> app> build.gradle:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-core:16.0.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-messaging:20.1.6'
}
apply plugin: 'com.google.gms.google-services'
android> build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
}
我不确定这是否是版本问题?
答案 0 :(得分:0)
关于发行说明
不再需要Firebase Android库firebase-core。这个 SDK包括适用于Google Analytics(分析)的Firebase SDK。
https://firebase.google.com/support/release-notes/android
另外,请使用Google Play服务插件版本4.3.3
classpath com.google.gms:google-services:4.3.3
答案 1 :(得分:0)
您可以像这样使用 firebase 的 bom(物料清单):
implementation platform('com.google.firebase:firebase-bom:27.1.0')
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
然后导入(在您的活动中):
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.messaging.FirebaseMessaging;
.
.
@Override
protected void attachBaseContext(Context newBase) {
FirebaseMessaging.getInstance().subscribeToTopic("all").addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.e("my_tag", "successfully register in topic");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("my_tag", e.getMessage());
}
});
}