我只是想学习如何使用firebase,因此我创建了一个完全空的应用程序,并想设置一个基础来开始尝试尝试,但是我遇到了这个错误。
我已经使用助手实施了firebase,并且仅放入两行代码中,firebase中的介绍指南正在提高输入。不知道我可以改变什么,因为我实际上什么都没有放。
这是导致崩溃的线
val database = FirebaseDatabase.getInstance()
有什么想法?
我已经看过人们问了这个问题的其他线程,但看来他们的代码可能已经改变了很多,或者答案已经指示的是我的情况。
这是我的主要活性
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 Build
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 build file
// 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
}
将Google Service版本更新为4.2.0
。
使用此
classpath 'com.google.gms:google-services:4.2.0'
而不是
classpath 'com.google.gms:google-services:4.1.0'