0

In my main Activity right after i try to initialize the two references it crashes, only to find out the error "FirebaseApp initialization unsuccessful"

private StorageReference mStorageReference; private DatabaseReference mDatabaseReference; mStorageReference = FirebaseStorage.getInstance().getReference("uploads"); mDatabaseReference = FirebaseDatabase.getInstance().getReference("uploads");

there is some code between the private declaration and the code itself, but that is not relevant to this problem

The manifest is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firebase10">

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

The build.gradle(Project):

buildscript {
   repositories {
      google()
      jcenter()
    }
    dependencies {
         classpath 'com.android.tools.build:gradle:3.3.1'
         classpath 'com.google.gms:google-services:4.1.0'
    }
 }

allprojects {
      repositories {
      google()
      jcenter()
     }  
}
task clean(type: Delete) {
   delete rootProject.buildDir
}

The build.gradle(app):

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

android {
      compileSdkVersion 28
      defaultConfig {
      applicationId "com.example.firebase10"
      minSdkVersion 19
      targetSdkVersion 28
      versionCode 1
      versionName "1.0"
      testInstrumentationRunner 
      "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android- 
        optimize.txt'), 'proguard-rules.pro'
        }
    }
 }

dependencies {
     api "com.google.android.gms:play-services-base:15.0.1"
     api "com.google.android.gms:play-services-auth:16.0.0"
     api "com.google.android.gms:play-services-identity:15.0.1"
     implementation fileTree(dir: 'libs', include: ['*.jar'])
     implementation 'com.android.support:appcompat-v7:28.0.0'
     implementation "com.android.support:customtabs:28.0.0"
     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
     implementation 'com.google.firebase:firebase-database:16.0.1'
     implementation 'com.google.firebase:firebase-storage:16.0.1'
     implementation 'com.google.firebase:firebase-auth:16.0.3'
     implementation 'com.android.support:recyclerview-v7:28.0.0'
     implementation 'com.android.support:cardview-v7:28.0.0'
     implementation 'com.squareup.picasso:picasso:2.71828'
     implementation 'com.google.gms:google-services:4.2.0'
     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'
}

I set up everything with Tools-Firebase, and i know that the code looks like it is glued together, since it is. I've been going through threads and just added things but nothing worked. If this matters, i am running the app on my phone, not emulator.

Raul Vaida
  • 13
  • 6
  • I cannot see in your code the implementation of the `firebase-core`. Have you aded `implementation 'com.google.firebase:firebase-core:16.0.7'`? – Alex Mamo Mar 17 '19 at 09:31
  • Added the implementation of the firebase-core, still crashing. Output:I/FirebaseInitProvider: FirebaseApp initialization unsuccessful – Raul Vaida Mar 17 '19 at 12:12
  • Possible duplicate of [FirebaseInitProvider: FirebaseApp initialization unsuccessful](https://stackoverflow.com/questions/37321728/firebaseinitprovider-firebaseapp-initialization-unsuccessful) – Martin Zeitler Apr 02 '19 at 12:25
  • "it's crashing" is not a proper error description. – Martin Zeitler Apr 02 '19 at 12:26

3 Answers3

0

Is your google-json file is well setted ?

Also Firebase needs time to connect to it server and gives you the instance referred to your device , give it some time or use a promise to make sure firebase is connected to it server and instance is generated, then perform the action that need firebase instance.

ismail alaoui
  • 5,748
  • 2
  • 21
  • 38
  • The google-json is downloaded from the project on firebase and put manually in the app folder. My copy-paste code is deceiving since i declare the private parts, then set up all the buttons and only after i set the FirebaseStorage and FirebaseDatabase. – Raul Vaida Mar 17 '19 at 12:01
0

In build.gradle(Project) I Changed 'com.google.gms:google-services:4.1.0' To 'com.google.gms:google-services:4.2.0' and the problem is solved

0

This one here is non-sense, because that's a Gradle plugin:

dependencies {
    implementation 'com.google.gms:google-services:4.2.0'
}

And this one belong to the bottom of the file:

apply plugin: 'com.google.gms.google-services'
Martin Zeitler
  • 1
  • 19
  • 155
  • 216