Reputation: 43
I need to connect to firebase, I did exactly what the firebase documentation told me that why I must've connected to firebase. I put the apply plugin as well, I saw the firebase console and I did every step I needed to do. that my code...
FirebaseApp.initializeApp(this);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef= database.getReference();
myRef.setValue("teste");
that is my build.code(module)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "projeto.ufma.com.projeto"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-database:16.0.5'
}
But always I'm getting that error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: projeto.ufma.com.projeto, PID: 28861
java.lang.RuntimeException: Unable to start activity ComponentInfo{projeto.ufma.com.projeto/projeto.ufma.com.projeto.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process projeto.ufma.com.projeto. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process projeto.ufma.com.projeto. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.4:240)
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database@@16.0.5:67)
at projeto.ufma.com.projeto.MainActivity.onCreate(MainActivity.java:60)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
The point is I followed the firebase documentation and I did everything there told me to do, though I can't connect to firebase.
I was trying to test the connection, but I just can...
Upvotes: 0
Views: 1196
Reputation: 984
Under Gradle Scripts - > build.gradle(Project:YourProjectName) in that file use latest classpath of play services buildscript - > dependencies - >
dependencies {
classpath 'com.google.gms:google-services:4.2.0'
}
Upvotes: 1