gpt4 book ai didi

android - 完全空的应用程序上的 "Default FirebaseApp is not initialized in this process"

转载 作者:行者123 更新时间:2023-11-29 18:34:19 26 4
gpt4 key购买 nike

我只是想学习如何使用 Firebase,所以我创建了一个完全空的应用程序并想设置一个基础来开始尝试一些东西,但我收到了这个错误。

我已经使用助手实现了 Firebase,并且只放入了 Firebase 中的介绍指南正在指示输入的两行代码。不知道我能改变什么,因为我实际上什么都没有放进去。

这是导致崩溃的行

val database = FirebaseDatabase.getInstance()

有什么想法吗?

我查看了其他线程,人们在这些线程中提出了这个问题,但似乎他们的代码有更多可以更改的内容,或者答案所指示的内容已经适用于我的情况。

这是我的主要 Activity

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

FirebaseApp.initializeApp(this)

val database = FirebaseDatabase.getInstance()
val myRef = database.getReference("message")


}
}

这是我的应用程序 Gradle 构建

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 28
defaultConfig {
applicationId "co.getdere.firebaseexperiments"
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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.1.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'
}

这是项目的 Gradle 构建文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

最佳答案

更新谷歌服务版本到4.2.0

使用这个

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

代替

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

关于android - 完全空的应用程序上的 "Default FirebaseApp is not initialized in this process",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54903726/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com