【问题标题】:Android Studio: Gradle Build Error No repositories are definedAndroid Studio:Gradle 构建错误未定义存储库
【发布时间】:2018-04-22 01:13:22
【问题描述】:

Andriod Studio 3.3.1

毕业 4.4

我通过 Android > Tools > Firebase 选项添加了 firebase 存储。但是,当我同步 gradle 时,构建失败。这是我得到的错误:

Cannot resolve external dependency com.google.gms:google-services:3.2.1 
because no repositories are defined. Required by:project :app

有人知道如何纠正这个错误吗?

build.gradle(模块:APP)

apply plugin: 'com.android.application'

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.google.firebase:firebase-core:15.0.0'
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    implementation 'com.google.firebase:firebase-auth:15.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:design:27.1.1'
    //implementation 'com.google.android.gms:play-services:11.0.4'
}

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

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

【问题讨论】:

    标签: android android-studio android-gradle-plugin build.gradle


    【解决方案1】:

    就我而言,我必须将以下代码添加到项目级 gradle:

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

    【讨论】:

      【解决方案2】:

      该错误表明缺少repositories,以便确定从哪里下载google-services

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

      jcenter 是对bintray jcenter 的引用。 Gradle 可以在那里找到google-services:3.2.1

      【讨论】:

        【解决方案3】:

        在我的情况下,我可以通过将另一个存储库范围添加到顶层来使其工作。

        repositories {
            mavenLocal()
            mavenCentral()
        }
        

        this example 启发了我这样做。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-09-01
          • 1970-01-01
          • 1970-01-01
          • 2016-05-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多