尽管我在build.gradle中添加了实现,但编译器无法解析任何Firebase类
应用程序级别build.gradle
apply plugin: 'com.android.application'
repositories {
google ()
mavenLocal()
flatDir {
dirs 'libs'
}
jcenter()
}
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.google.firebase.udacity.friendlychat"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:26.2.0'
implementation 'com.android.support:appcompat-v7:26.2.0'
// Displaying images
implementation 'com.github.bumptech.glide:glide:3.6.1'
}
apply plugin: 'com.google.gms.google-services'
项目级别build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenLocal()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha17'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
在主要活动中,IDE无法解析这些类中的任何一个,并且编译失败
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mMessagesDatabaseReference;
private ChildEventListener mChildEventListener;
private FirebaseAuth mFirabaseAuth;
我已将Gradle文件与项目同步,尝试过清理项目,尝试过重建项目。
答案 0 :(得分:0)
点击文件->使用Gradle文件同步项目
有同样的问题,这对我来说已经解决了。
如果仍然无法正常运行,请尝试进行重建。
答案 1 :(得分:0)
在应用程序build.gradle中 添加依赖项
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-core:16.0.5'
答案 2 :(得分:0)
如果您尝试调用Firebase对象,并收到此错误:
错误:无法解析符号Firebase
您可能缺少依赖项。
确保将com.firebase:firebase-client添加到应用程序gradle中的依赖项中:
dependencies {
implementation 'com.firebase:firebase-client-android:2.5.2'
答案 3 :(得分:-1)
如果您只是从Firebase文档复制粘贴代码,然后将以下库添加到Java文件:
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;