0

i have used following dependencies. it gives me "Default FirebaseApp is not initialized in this process.Make sure to call FirebaseApp.initializeApp(Context) first."

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('org.apache.httpcomponents:httpcore:4.4.1') {
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'

}*/

/*Button*/
//Google Analytics
//Sweet Alert Dialog

compile('com.google.api-client:google-api-client-android:1.22.0')
compile('com.google.apis:google-api-services-script:v1-rev6-1.22.0') {
    exclude group: 'org.apache.httpcomponents'
}
/*Button*/
//Google Analytics
//Sweet Alert Dialog
compile 'pub.devrel:easypermissions:0.1.5'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.github.markushi:circlebutton:1.1'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'me.spark:submitbutton:1.0.1'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
compile 'com.google.android.gms:play-services-auth:9.8.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
testCompile 'junit:junit:4.12'
compile files('libs/org.apache.http.legacy.jar')
}
Dileep Patel
  • 1,988
  • 2
  • 12
  • 26

3 Answers3

0

This has little to do with your dependencies, you'll need to initialize Firebase before using it in your code.

So at the very beginning (Or at least before you make any references to Firebase) add the following:

FirebaseApp.initializeApp(getContext());
Raymond
  • 2,276
  • 2
  • 20
  • 34
0

In Your Project gradle file put this dependancy

classpath 'com.google.gms:google-services:3.0.0'

and than your module gradle

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.google.firebase:firebase-messaging:10.0.1'

}
apply plugin: 'com.google.gms.google-services'

it Work for me.

Payal Sorathiya
  • 756
  • 1
  • 8
  • 23
0

Put this line at the bottom of your app build.gradle file (* last statement)

apply plugin: 'com.google.gms.google-services'

and also check if you are using this dependency in upper gradle file

dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        //classpath 'com.android.tools.build:gradle:2.0.0'
        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
    }

You have to initialize Firebase befor you use it and best place to initialize it in Application Class

public class App extends BaseApplication {
    public static App _appContext = null;
    public static final String TAG = App.class.getSimpleName();

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        _appContext = this;
        Firebase.setAndroidContext(getApplicationContext());
        FirebaseApp.initializeApp(getContext());
    }
}

And add it to mainifiest file Application Tag like

<application
        android:name="your.path.to.App"
        .
        .>

Than try and let me know

You can try this Remove:

Firebase.setAndroidContext(this);
FirebaseApp.initializeApp(this);

And put:

FirebaseDatabase database = FirebaseDatabase.getInstance();
Sushant Gosavi
  • 3,647
  • 3
  • 35
  • 55