我有一个大问题。
我正在开发一个使用Firebase发送推送消息的应用。我按照谷歌的教程 - > link
问题出现了,当我在应用程序打开时签署APK时,它会在事件显示之前崩溃,但这不会发生在我编码时(调试中的应用程序)
崩溃报告是:
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.res.Resources.getResourcePackageName(int)' on a null object reference
at android.app.ActivityThread.installProvider(ActivityThread.java:6770)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6362)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6302)
at android.app.ActivityThread.access$1800(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1861)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.res.Resources.getResourcePackageName(int)' on a null object reference
at com.google.android.gms.common.internal.zzah.<init>(Unknown Source)
at com.google.firebase.FirebaseOptions.fromResource(Unknown Source)
at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1789)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1764)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:6767)
... 10 more
我在SO中看到不同的帖子,在build.gradle文件中未设置applicationId:xx.xx.xx
时发生错误。但我知道了。
所以我不知道问题出在哪里,我不明白为什么在调试模式下它工作得很完美,但是在发布模式下不是。此外,我在app模块中有google-services.json文件。
我该如何解决?
在build.gradle文件(app)中:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "es.in2.otr.app.im"
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
testApplicationId "es.in2.otr.app.im.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
dexOptions {
javaMaxHeapSize "4g" //specify the heap size for the dex process
}
lintOptions{
checkReleaseBuilds false
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
useLibrary 'org.apache.http.legacy'
}
dependencies {
...
...
...
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okio:okio:1.9.0' /*Used for OKHTTP*/
...
...
...
apply plugin: 'com.google.gms.google-services'
}
更新:
google-service.json和内容
的图片{
"project_info": {
"project_number": "283882435243",
"firebase_url": "https://XXXXX.firebaseio.com",
"project_id": "XXXXX",
"storage_bucket": "XXXXX.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:XXXXX:android:XXXXX",
"android_client_info": {
"package_name": "es.in2.otr.app.im"
}
},
"oauth_client": [
{
"client_id": "XXXXX.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "es.in2.otr.app.im",
"certificate_hash": "A0XXXXXXXXXXXXXXXXXXXXXXXXXAA"
}
},
{
"client_id": "2XXXXX.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaXXXXXXXXXXXXXXXXXXXXXXXXXUTM"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 2,
"other_platform_oauth_client": [
{
"client_id": "XXXXX.apps.googleusercontent.com",
"client_type": 3
}
]
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
FIREBASE控制台: