我正在使用Firebase数据库在Android上工作...。使用连接到Firebase的Firebase工具,并使用该语句添加了Firebase数据库
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
我能够导入数据库参考,但不能导入FirebaseDatabase
我的gradle(app)文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.yadav.yadavapp"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
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'
implementation 'com.android.support:support-annotations:27.1.1'
}
apply plugin: 'com.google.gms.google-services'
我的主活动文件
package com.example.yadav.yadavapp;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.firebase.database.DatabaseReference; ///working
import com.google.firebase.database.FirebaseDatabase; //cannot import
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
答案 0 :(得分:0)
这是不合逻辑的,因为它是同一个程序包。
Android Studio只会删除所有未使用的导入
... 除非在MainActivity
中使用它们。
例如:
public class MainActivity extends AppCompatActivity {
/* when declaring these, it should import both of them */
protected FirebaseDatabase fb = FirebaseDatabase.getInstance();
protected DatabaseReference defaultRef = null;
public MainActivity() {}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}