我正在 Android 上开发一个使用 Firebase 数据库的程序,但我现在遇到了问题。这是我的代码 MainActivity:public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("message"); // Read from the database myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { String value = dataSnapshot.getValue(String.class); Log.d("TAG", "Value is: " + value); } @Override public void onCancelled(DatabaseError error) { Log.w("TAG", "Failed to read value.", error.toException()); } }); }}和我的依赖:dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.google.firebase:firebase-database:16.0.6' implementation 'com.google.firebase:firebase-core:16.0.7' 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'}到目前为止,我发现的结果与我应该添加的代码行一致,并且我已经这样做了,但我还没有听说要删除错误。public class Application extends android.app.Application { @Override public void onCreate() { super.onCreate(); FirebaseApp.initializeApp(this); }}
1 回答
Qyouu
TA贡献1786条经验 获得超11个赞
您的依赖项中似乎缺少 google-services 插件。firebase android 文档提到应该添加这些插件:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.2.0' // google-services plugin
}
}
allprojects {
// ...
repositories {
google() // Google's Maven repository
// ...
}
}
添加回答
举报
0/150
提交
取消