簡體   English   中英

無法解析 ':app@debug/compileClasspath' 的依賴:無法解析 com.google.android.gms:play-services-basement:[15.0.0,16.0.0)

[英]Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-basement:[15.0.0,16.0.0)

我收到此錯誤:這是我的 build.gradle(Module:app)

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.mycompany.myapp"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding.enabled = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.firebase:firebase-core:15.0.0'
    compileOnly "org.projectlombok:lombok:1.16.20"
    annotationProcessor 'org.projectlombok:lombok:1.16.20'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.0'
    implementation 'com.google.android.gms:play-services-location:15.0.0'
    implementation 'com.google.android.gms:play-services-places:15.0.0'
    implementation 'com.paytm.pgsdk:pgsdk:1.0.8'
    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'
    compile 'com.crashlytics.sdk.android:crashlytics:2.9.1'
}

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

這是我的 build.gradle(Project: myApp)

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'io.fabric.tools:gradle:1.25.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
        }
    }
}

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

我檢查了其他解決方案,其中大多數建議添加

maven { url "https://maven.google.com" }

到項目的 build.gradle。 我已經嘗試過這個,但我仍然遇到同樣的錯誤。

我在 android studio 3.0 上。 我也嘗試添加google()而不是 maven(另一個建議)

選項1:

請按照以下說明解決。

項目級 build.gradle

maven { url "https://www.jitpack.io" }

代替

maven { url "https://jitpack.io" }

選項 2:

項目級 build.gradle

google()存儲庫應該是第一優先級

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

選項 3:

請按照以下步驟解決。

第1步:

項目級 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0' // google-services plugin
        classpath 'com.android.tools.build:gradle:3.4.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

第2步:

應用級 build.gradle

我有更新 One Signal 版本。

implementation 'com.onesignal:OneSignal:3.11.1'

代替

implementation 'com.onesignal:OneSignal:3.10.9' 

轉到文件 → 其他設置 → 默認設置 → 構建、執行、部署 → 構建工具 → Gradle → 取消選中Offline work選項。

我在使用 OneSignal 處理我的 android 應用程序中的推送通知時遇到了同樣的問題。

解決方案是將 exclude 子句添加到其依賴項中:

implementation ('com.onesignal:OneSignal:3.8.3'){
    exclude group: 'com.google.android.gms'
}

在 app 文件夾中,然后手動添加任何其他缺少的依賴項,例如:

implementation 'com.google.android.gms:play-services-appinvite:16.1.0'

問題是 OneSignal SDK 包含的 Google Play 服務依賴項與我在應用程序中使用的最新版本的 gms 和 firesbase 的版本不同。

所以我建議你找出你添加的一個在項目中使用 google play 服務的依賴項,並在其上使用 exclude 子句。 盡管如果您的系統連接到互聯網,您的 gradle 應該會構建。

希望這是有幫助的。

我正在使用 VPN 進行互聯網連接。 我關閉了 VPN,它對我有用。

如果您在項目build.gradle中聲明了以下內容

maven { url "https://jitpack.io" }

嘗試更改為

maven { url "https://www.jitpack.io" }

使用 VPN 解決了​​我的問題。

我遇到了這個問題,我以前使用過代理。 我發現我的代理不再工作,所以我去設置並將代理配置更改為自動,但仍然顯示相同的錯誤。

我終於發現代理也自動設置為 gradle,但是當我禁用它時,它並沒有從我的 gradle 配置中刪除。 所以我去了C:Users/User/.gradle/gradle.properties並且在那個文件中有這樣的東西:

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#enter code here
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Sat Aug 31 18:23:27 IRDT 2019
systemProp.https.proxyPort=8118
systemProp.http.proxyHost=fodev.org
systemProp.https.proxyHost=fodev.org
systemProp.http.proxyPort=8118

所以我只是編輯了這個文件並評論了最后 4 行,它解決了我的問題。

我也在使用 VPN 服務。

我的問題是...
我可以運行該項目...但突然出現此錯誤。
經過幾次嘗試“再試一次”解決方案但沒有解決。

終於過了幾分鍾就白費了。 我嘗試清潔項目。 和重建。 Tadaaaa它的工作。
我不知道這是否會幫助任何人,但它解決了我的問題。 希望它能解決你的問題。

打開頂級 build.gradle 文件並添加 google-services:

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

此外,如果您已經添加了它,只需將 google-service 和 gradle 更新到最新

如果您突然出現此問題,可能是在生成 apk 時它已損壞。 這很少發生

解決方案:重建任務

你可以在這張圖片中看到它

將存儲庫更新到最新版本為我解決了這個問題。

implementation 'com.google.android.gms:play-services-ads-identifier:17.0.1'

在我的情況下,我只是將我的項目級別構建 Gradle 和其他依賴項更改為最新版本,並將應用程序級別構建 gradle 中的 Google Maps 依賴項更改為 10.0.0。

您是否嘗試在您的依賴項中添加此內容:

implementation 'com.google.android.gms:play-services-basement:15.0.0'

Just Build → Clean Project 對我有用

暫無
暫無

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

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