首页 > 解决方案 > FirebaseApp 初始化不成功 - 错误崩溃应用程序

问题描述

在我尝试初始化它崩溃的两个引用之后,在我的主要活动中,只是发现错误“FirebaseApp 初始化不成功”

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

私有声明和代码本身之间有一些代码,但这与这个问题无关

清单是:

<?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>

build.gradle(项目):

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
}

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'
}

我使用 Tools-Firebase 设置了所有内容,并且我知道代码看起来像是粘在一起的,因为它是。我一直在经历线程,只是添加了一些东西,但没有任何效果。如果这很重要,我在手机上运行应用程序,而不是模拟器。

标签: javaandroidfirebasegoogle-play-services

解决方案


在 build.gradle(Project) 我将'com.google.gms:google-services:4.1.0'更改为'com.google.gms:google-services:4.2.0'问题就解决了


推荐阅读