代码之家  ›  专栏  ›  技术社区  ›  Val

Android Studio:Gradle构建错误未定义存储库

  •  6
  • Val  · 技术社区  · 6 年前

    Andriod Studio 3.3.1

    gradle 4.4

    我通过Android添加了firebase存储>工具(>);Firebase选项。然而,当我同步渐变时,构建失败。这是我得到的错误:

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

    有人知道如何更正此错误吗?

    建筑gradle(模块:应用程序)

    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'
    
    3 回复  |  直到 6 年前
        1
  •  9
  •   Jithin Jude kandroidj    5 年前

    在我的情况下,我必须向项目级gradle添加以下代码:

    allprojects {
        repositories {
            google()
            jcenter()
    
        }
    }
    
        2
  •  4
  •   xiaomi    6 年前

    错误表明 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
  •  1
  •   Naruto Sempai    6 年前

    在我的例子中,我能够通过向顶层添加另一个存储库范围来实现它。

    repositories {
        mavenLocal()
        mavenCentral()
    }
    

    我的灵感来自 this example