【问题标题】:Cannot resolve external dependency com.google.gms:google-services:4.2.0 because no repositories are defined. Android Studio 3.5无法解析外部依赖项 com.google.gms:google-services:4.2.0,因为没有定义存储库。安卓工作室 3.5
【发布时间】:2019-09-06 13:06:53
【问题描述】:

无法解析外部依赖项 com.google.gms:google-services:4.2.0,因为未定义存储库。

我已经尝试了 Stack Overflow 的很多解决方案,但没有一个我提到的解决方案对我有用

这是我的项目级 build.gradle

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

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

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

这是我的应用级 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.4'
    implementation 'com.google.firebase:firebase-database:16.0.4'
    implementation 'com.google.firebase:firebase-storage:16.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'com.google.firebase:firebase-analytics:17.0.1'
}

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

程序同步后,它给我这个错误“无法解析外部依赖项 com.google.gms:google-services:4.2.0,因为没有定义存储库。”

【问题讨论】:

    标签: android android-studio


    【解决方案1】:

    我遇到了类似的问题,我通过添加解决了它,

    repositories {
            google()
            jcenter()
        }
    

    到 build.gradle(Module:app) 文件中的 buildscript。祝你有美好的一天

    【讨论】:

      【解决方案2】:

      尝试在“app”级别的 gradle 文件中添加以下内容

      repositories {
          mavenCentral()
      }
      

      【讨论】:

        【解决方案3】:

        在 build.gradle 应用级别添加如下 sn -p

        repositories {
            google()
            jcenter()
        }
        

        例如

        buildscript {
            repositories {
                google()
                jcenter()
            }
            dependencies {
                classpath 'com.google.gms:google-services:4.3.3'
            }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-14
          • 2022-01-16
          • 2021-06-24
          • 2022-08-03
          • 2019-06-23
          • 2014-07-09
          相关资源
          最近更新 更多