0

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.augmentedreality.projectar. Make sure to call FirebaseApp.initializeApp(Context) first.

For the past 48 hours I've been stuck at this Exception, and so far has no clue what's possibly causing this, I've referred all these answers:

And yet the problem persists. I am using Firebase Storage as well as Firebase Database. I use Firebase storage to download image using a Service. The Service is same as the Firebase quick start example from Github[here].

Now, the exception is thrown at this line :

    mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl("https://firebasestorage.googleapis.com/v0/b/xxxxxxx-xx-xxxxxx.appspot.com/o/Coca-Cola.jpg?alt=media&token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx");

Based on the answers mentioned in the aforementioned questions, I've made the following changes:

1)AppMain.java

    public class AppMain extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseApp.initializeApp(this);
        Firebase.setAndroidContext(this);
        //if(!FirebaseApp.getApps(this).isEmpty()) {
        //    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
        //}
    }
}

2) Dependencies

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.firebase:firebase-core:9.6.1'
    compile 'com.google.firebase:firebase-database:9.6.1'
    compile 'com.firebase:firebase-client-android:2.5.2+'
    compile 'com.google.firebase:firebase-storage:9.6.1'
    compile 'com.google.android.gms:play-services:10.0.0'
}

Question: How to fix this issue?

Community
  • 1
  • 1
OBX
  • 6,044
  • 7
  • 33
  • 77
  • You could download the entire quickstart application and move your own code into it instead of pulling it apart to work with your own code. https://github.com/firebase/quickstart-android/tree/master/storage – OneCricketeer Dec 27 '16 at 15:40

2 Answers2

1

Remove

FirebaseApp.initializeApp(this);
Firebase.setAndroidContext(this);
compile 'com.firebase:firebase-client-android:2.5.2+'

you dont need them..

use

compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.firebase:firebase-storage:10.0.1'
compile 'com.google.android.gms:play-services:10.0.1'

private DatabaseReference mDatabase;
// ...
mDatabase = FirebaseDatabase.getInstance().getReference();

instead, for full instructions - Firebase Docs

Nirel
  • 1,855
  • 1
  • 15
  • 26
  • That doesn't make any difference! – OBX Dec 27 '16 at 14:52
  • 2
    Also remove `compile 'com.firebase:firebase-client-android:2.5.2+'`. Don't mix Firebase versions 2.x and >=9. – Frank van Puffelen Dec 27 '16 at 15:32
  • 2
    I would say also update the Firebase version to match the play services – OneCricketeer Dec 27 '16 at 15:37
  • I switched all dependencies to `10.0.1` , however I am unable to import Jackson classes, do I need a specific dependency now? – OBX Dec 27 '16 at 16:36
  • Jackson is no longer included in the Firebase SDK. If you still need it, you can import it explicitly. See http://stackoverflow.com/questions/37547399/how-to-deserialise-a-subclass-in-firebase-using-getvaluesubclass-class/37548330#37548330 – Frank van Puffelen Dec 27 '16 at 17:34
0

Instead of modifying this code, You should update the Android studio version. May be your problem will be solved.