我已按照这些说明操作,以便在我的应用中使用Firebase Messaging:https://www.youtube.com/watch?v=rq-Axj79iNo。不幸的是,当我在Firebase控制台的计算机上按“发送”时,我的应用程序立即崩溃。我收到此错误:
04-24 18:43:02.847 21312-21351/com.thisIsMyApplicationId E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
Process: com.thisIsMyApplicationId, PID: 21312
java.lang.AbstractMethodError: abstract method "void com.google.firebase.iid.zzb.handleIntent(android.content.Intent)"
at com.google.firebase.iid.zzb$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
也许这可能是我的问题的原因:我的应用程序根本不需要许可。如果我想使用Firebase Messaging,是否需要权限?或者是别的什么。我该如何解决这个问题?
一些有用的文件:
在App Directory上的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.myApplicationId"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
Gradle目录中的build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
其余的,我将google-services.json添加到我的App Directory。
除了这些文件外,我没有更改任何其他文件。
如何解决上述问题?
答案 0 :(得分:0)
您使用de core 10.2.1和messaging:9.0.0
你应该使用:
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
我希望它能帮到你
答案 1 :(得分:0)
问题是,您的应用无权使用互联网,否则,您无法从Firebase收到任何通知,因为Firebase邮件来自互联网!
将这些行添加到AndroidManifest.xml中,作为manifest的直接子项:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
希望这会有所帮助!