Reputation: 747
I recently started working with Google Firebase for Android. I had some trouble with it. But I tried to setup the Firebase manually now I am getting a new error. I am sure that it has to do something with the gradle.
My build.gradle(app):
apply plugin: 'com.android.application'
//apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.example.nirmal.ilistensinch"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
/*androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})*/
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
testCompile 'junit:junit:4.12'
compile files('/media/win/Android Apps/IlistenSinch/sinch-android-rtc-3.9.10.jar')
}
My build.gradle(project):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
// apply plugin: 'com.google.gms.google-services'
// 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
}
but when I run the code I am getting the following error
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.nirmal.ilistensinch. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.example.nirmal.ilistensinch.SinchLoginActivity.onCreate(SinchLoginActivity.java:46)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
If you notice my build.gradle(app)
you can see that I have commented apply plugin: 'com.google.gms.google-services'
If I take out that comment I am getting this error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/api/zza.class
Any idea on how to solve this problem?
Upvotes: 1
Views: 254
Reputation: 7720
Put the apply plugin: 'com.google.gms.google-services'
at the bottom of your app's build.gradle
...
testCompile 'junit:junit:4.12'
compile files('/media/win/Android Apps/IlistenSinch/sinch-android-rtc-3.9.10.jar')
}
apply plugin: 'com.google.gms.google-services'
You should read this official Firebase setup guide for Android
Upvotes: 3