我按照这里的说明https://firebase.google.com/docs/android/setup
android 应用程序编译成功,但是一旦我将它安装到我的设备上,它就崩溃了
07-07 12:42:43.534 5450 5450 E AndroidRuntime: java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.NullPointerException: Application context cannot be null.
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:5177)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.app.ActivityThread.installContentProviders(ActivityThread.java:4769)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4709)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.app.ActivityThread.-wrap1(ActivityThread.java)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5443)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: Caused by: java.lang.NullPointerException: Application context cannot be null.
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.google.android.gms.common.internal.zzaa.zzb(Unknown Source)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
07-07 12:42:43.534 5450 5450 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:5174)
07-07 12:42:43.534 5450 5450 E AndroidRuntime:
... 10 更多
我尝试了Unable to get provider com.google.firebase.provider.FirebaseInitProvider中的解决方案,但这没有帮助。
我添加了 google-gms 依赖项并将 google-services.json 添加到 app/
这是我的 app/build.gradle
apply plugin: 'com.android.application'
Repositories{
mavenCentral()
}
android {
project.archivesBaseName = "x_mno";
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion "22.0.1"
enforceUniquePackageName=false
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
java.srcDirs = ['src']
aidl.srcDirs = ['src']
}
}
defaultConfig {
applicationId "com.example.ccc.mno"
minSdkVersion 23
targetSdkVersion 23
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
lintOptions {
abortOnError false
}
}
configurations {
}
dependencies {
compile group: 'com.google.android.gms', name: 'play-services', version: '9.0.2'
compile group: 'com.android.support', name: 'support-v4', version: '23.0'
//aded this
compile 'com.google.firebase:firebase-core:9.0.1'
}
//aded this
apply plugin: 'com.google.gms.google-services'
这是我的根级 build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.+'
// added this
classpath 'com.google.gms:google-services:3.0.0'
} }