java.lang.IllegalStateException:名为 [DEFAULT] 的 FirebaseApp 不存在"FirebaseStorage"



每当我尝试在此链接中测试样本时,我都会得到此错误[https://firebase.google.com/docs/storage/android/start]

FirebaseApp with name [DEFAULT] doesn't exist.

我的gradle文件是

buildscript {
repositories {
    jcenter()
}
dependencies {
        //classpath 'com.android.tools.build:gradle:0.12.+'
        classpath 'com.android.tools.build:gradle:0.14.+'
        classpath 'com.google.gms:google-services:3.0.0'
}
}
 apply plugin: 'com.android.application'
 apply plugin: 'android'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
            compile 'com.google.firebase:firebase-invites:9.6.1'
          compile 'com.google.firebase:firebase-server-sdk:3.0.1'
// Google Play Services
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.android.gms:play-services-gcm:9.6.1'
compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.google.android.gms:play-services-location:9.6.1'
// Firebase Client
compile 'com.firebase:firebase-client-android:2.5.2'
compile 'com.firebaseui:firebase-ui-database:0.6.0'
compile 'com.google.firebase:firebase-auth:9.6.1'
compile 'com.google.firebase:firebase-database:9.6.1'
//Storage and authin
compile 'com.google.firebase:firebase-storage:9.6.1'
//multidex
compile 'com.android.support:multidex:1.0.1'

}
android {
compileSdkVersion 21
buildToolsVersion "24"
defaultConfig {
applicationId "com.pay.my_admin"
minSdkVersion 21
targetSdkVersion 24
multiDexEnabled true
 }
  afterEvaluate {
  tasks.matching {
  it.name.startsWith('dex')
  }.each { dx ->
  if (dx.additionalParameters == null) {
     dx.additionalParameters = ['--multi-dex']
  } else {
     dx.additionalParameters += '--multi-dex'
  }
  }
  }
  buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
                                             'proguard-rules.pro'
    }
   }
 compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }

 sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }
    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')
    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debu   /AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
}
}
apply plugin: 'com.google.gms.google-services'

我已经检查了其他人的问题,并尝试了他们建议的解决方案,但问题仍然如此。

请注意,我正在使用Eclipse。

我也有相同的错误。我认为您应该在获得Firebasestorage的对象之前登录。

将此代码放入启动器活动的onCreate()中

FirebaseAuth mAuth = FirebaseAuth.getInstance(); 

然后在onstart()中检查firebaseuser值。如果用户为null,请匿名登录。

FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
  // do your stuff
} else {
  signInAnonymously();
}

signAnynyly()

private void signInAnonymously() {
    mAuth.signInAnonymously().addOnSuccessListener(this, new  OnSuccessListener<AuthResult>() {
            @Override
            public void onSuccess(AuthResult authResult) {
                // do your stuff
            }
        })
        .addOnFailureListener(this, new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                Log.e(TAG, "signInAnonymously:FAILURE", exception);
            }
        });
}

相关内容

  • 没有找到相关文章

最新更新