簡體   English   中英

無法解析外部依賴項 com.google.gms:google-services:4.2.0,因為沒有定義存儲庫。 安卓工作室 3.5

[英]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,因為沒有定義存儲庫。

我從 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,因為沒有定義存儲庫。”

我遇到了類似的問題,我通過添加解決了它,

repositories {
        google()
        jcenter()
    }

的build.gradle(模塊:應用程序)buildscript文件。 祝你今天過得愉快

嘗試在“應用”級別的 gradle 文件中添加以下內容

repositories {
    mavenCentral()
}

在 build.gradle 應用程序級別添加以下代碼段

repositories {
    google()
    jcenter()
}

例如

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM