将我的Android Studio项目连接到Firebase时出错

时间:2019-07-17 12:38:09

标签: android-studio

我想将Android Studio连接到Firebase,但是出现此错误:

  

错误:无法解析':app @ debug / compileClasspath'的依赖关系:无法解析androidx.appcompat:appcompat:1.0.2。   显示详细资料   受影响的模块:应用

  

错误:无法解析':app @ debug / compileClasspath'的依赖关系:无法解析androidx.constraintlayout:constraintlayout:1.1.3。   显示详细资料   受影响的模块:应用

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.socialnetwork"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

1 个答案:

答案 0 :(得分:0)

首先,我建议您转到Firebase Docs以获取更多信息

也在您的android studio中...您需要使缓存无效。.

转到文件> 使缓存无效\重新启动> 使无效

转到Firebase Console添加您的项目。

下载 google-services.json 文件并将其添加到您的目录

然后在build.gradle文件中添加classpath 'com.google.gms:google-services:4.2.0'

build.gradle:

  dependencies {
    // Add the following line:
    classpath 'com.google.gms:google-services:4.2.0'  // Google Services plugin
  }

之后,在您的 app / build.gradle 文件中:应该看起来像这样


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
   //FireBase
   implementation 'com.google.firebase:firebase-core:17.0.1'
}
//add this line
apply plugin: 'com.google.gms.google-services'

然后同步您的项目