Android 无法解析符号Firebase

Android 无法解析符号Firebase,android,firebase,gradle,Android,Firebase,Gradle,尽管我在build.gradle中添加了implementation,但编译器不会解析任何Firebase类 apply plugin: 'com.android.application' repositories { google () mavenLocal() flatDir { dirs 'libs' } jcenter() } android { compileSdkVersion 26 buildToolsVe

尽管我在build.gradle中添加了implementation,但编译器不会解析任何Firebase类

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'
// 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
}
应用程序级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'
// 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
}
项目级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'
// 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文件同步,我已尝试清理项目,我已尝试重建项目。

单击文件->将项目与gradle文件同步

有同样的问题,这为我解决了

如果仍然不起作用,请尝试重新构建。

在app build.gradle中 添加依赖项

implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-core:16.0.5'

如果您试图调用Firebase对象,并且出现以下错误:

错误:无法解析符号Firebase

您可能缺少依赖项

确保将com.firebase:firebase客户端添加到应用程序gradle:

dependencies {

    implementation 'com.firebase:firebase-client-android:2.5.2'

如果您只是复制粘贴firebase文档中的代码,请将以下库添加到java文件中:

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

最后一个应该是FirebaseAuth,而不是FiraBaseAuth谢谢你的提示。这并没有纠正我曾经犯过的错误。但我确实通过将firebase数据库从16.0.1更改为16.0.0,然后再返回到16.0.1来修复它。奇怪的