【问题标题】:Unable to resolve dependencies with Android Studio and Firebase无法使用 Android Studio 和 Firebase 解决依赖关系
【发布时间】:2020-02-16 13:30:12
【问题描述】:

以下是我得到的错误,请帮助我!

错误:无法解析 ':app@debug/compileClasspath' 的依赖关系:

无法解析 com.google.firebase:firebase-core:17.2.0。

错误:无法解析 ':app@debug/compileClasspath' 的依赖关系:

无法解析 com.google.firebase:firebase-config:19.0.3。

错误:无法解析 ':app@debug/compileClasspath' 的依赖关系:

无法解析 com.google.android.gms:play-services-measurement-base:[17.2.0]。

错误:无法解析 ':app@debug/compileClasspath' 的依赖关系:

无法解析 com.google.android.gms:play-services-measurement-impl:[17.2.0]。

错误:无法解析 ':app@debug/compileClasspath' 的依赖关系:

无法解析 com.google.android.gms:play-services-measurement-sdk-api:[17.2.0]。

错误:无法解析 ':app@debugAndroidTest/compileClasspath' 的依赖关系:

无法解析 com.google.firebase:firebase-core:17.2.0。

错误:无法解析 ':app@debugAndroidTest/compileClasspath' 的依赖关系:

无法解析 com.google.firebase:firebase-config:19.0.3。

错误:无法解析 ':app@debugAndroidTest/compileClasspath' 的依赖关系:

无法解析 com.google.android.gms:play-services-measurement-base:[17.2.0]。

错误:无法解析 ':app@debugAndroidTest/compileClasspath' 的依赖关系:

无法解析 com.google.android.gms:play-services-measurement-impl:[17.2.0]。

错误:无法解析 ':app@debugAndroidTest/compileClasspath' 的依赖关系:无法解析 com.google.android.gms:play-services-measurement-sdk-api:[17.2.0]。

错误:无法解析 ':app@debugUnitTest/compileClasspath' 的依赖关系:无法解析 com.google.firebase:firebase-core:17.2.0。

错误:无法解析 ':app@debugUnitTest/compileClasspath' 的依赖关系:无法解析 com.google.firebase:firebase-config:19.0.3。

错误:无法解析 ':app@debugUnitTest/compileClasspath' 的依赖关系:无法解析 com.google.android.gms:play-services-measurement-base:[17.2.0]。

错误:无法解析 ':app@debugUnitTest/compileClasspath' 的依赖关系:无法解析 com.google.android.gms:play-services-measurement-impl:[17.2.0]。

错误:无法解析 ':app@debugUnitTest/compileClasspath' 的依赖关系:无法解析 com.google.android.gms:play-services-measurement-sdk-api:[17.2.0]。

//app level build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.hfad.firebaselinkedin"
        minSdkVersion 16
        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.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.firebase:firebase-core:17.2.0'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-config:19.0.3'
    implementation 'com.google.firebase:firebase-auth:19.1.0'



}
apply plugin: 'com.google.gms.google-services'
//project level build.gradle

buildscript {
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.3.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

标签: java android firebase firebase-realtime-database firebase-authentication


【解决方案1】:

更新

  1. 尝试“文件”->“使缓存无效/重新启动 -> 无效并重新启动”
  2. 尝试清理项目下的 .gradle 和 .idea 目录 根目录。

转到文件->其他设置->默认设置(新项目的设置在较新的版本中)->构建,执行, 部署 -> 构建工具 -> Gradle -> 并取消选中离线工作选项。

来自这个answer

如果您使用VPN,请在同步之前关闭它或更改IP,因为有些IP被谷歌阻止,因为它们可能被用来对谷歌进行DDOS攻击

如果上述步骤对您没有帮助,请在您的项目级别尝试 build.gradle

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }           
        maven { url "https://maven.google.com" } // Google's Maven repository - FCM
        maven {
            url 'https://dl.bintray.com/azeesoft/maven'
        }
        google()
        jcenter()
        mavenCentral()
    }
}

【讨论】:

  • 以上都试过了,仍然给我同样的错误。我通过热点使用移动数据,所以我不认为互联网是这里的问题。而且我的离线工作总是不受检查。
  • 我在更新会话中添加了以上步骤,您也可以试试这些吗?
  • 显然它给了我同样的错误。不知道发生了什么。
  • 最后一步是“卸载你的 Android Studio 并重新安装更新的版本……”这就是我现在所知道的全部
  • 我已经在使用最新版本,Android Studio 3.5.1。我能够将我的项目连接到除分析之外的所有大多数 Firebase 服务。
猜你喜欢
  • 2015-05-09
  • 2016-03-06
  • 2018-04-22
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多