Android Studio 3.5 错误:无法解析“:app@debug/compileClasspath”的依赖关系

Posted

技术标签:

【中文标题】Android Studio 3.5 错误:无法解析“:app@debug/compileClasspath”的依赖关系【英文标题】:Android Studio 3.5 ERROR: Unable to resolve dependency for ':app@debug/compileClasspath' 【发布时间】:2019-12-31 18:38:10 【问题描述】:

我在尝试同步 gradle 时遇到此错误。我正在使用 Android Studio 3.5gradle 5.4.1 。它在这个配置下运行良好,但突然我开始收到这个错误。

**ERROR**: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-location:[15.0.0, 16.0.0).
Affected Modules: app

**ERROR**: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-location:[15.0.0, 16.0.0).
Affected Modules: app

**ERROR**: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.firebase:firebase-messaging:[10.2.1, 12.1.0).
Affected Modules: app

**ERROR**: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-location:[10.2.1, 12.1.0).
Affected Modules: app

这是我的app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'com.apollographql.android'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'io.fabric'

def versionMajor = 4
def versionMinor = 0
def versionPatch = 0
def versionBuild = 345

def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android 
    signingConfigs 
        config 
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        
    
    compileSdkVersion 29
    defaultConfig 
        applicationId "example"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "$versionMajor.$versionMinor.$versionPatch.$versionBuild"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [auth0Domain: "@string/com_auth0_domain", auth0Scheme: "demo"]
        setArchivesBaseName new Date().format("dd.MMM.yy") + "-v#" + versionName

        //OneSignal
        manifestPlaceholders = [
                onesignal_app_id: 'id',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: 'REMOTE'
        ]

        // add some strings to res
        resValue('string', 'google_maps_api_key', google_maps_api_token)
        resValue('string', 'google_maps_places_api_key', google_maps_places_api_token)
        buildConfigField("String", "API_TOKEN", "\"$api_token\"")
        buildConfigField("String", "ADJUST_TOKEN", "\"$adjust_token\"")
        buildConfigField("String", "GRAPH_QL", "\"$api_graphql\"")

        renderscriptTargetApi 28
        renderscriptSupportModeEnabled true
    
    buildTypes 
        release 
            minifyEnabled false
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField("String", "SERVER_URL", "\"$api_base_url$api_ext_release\"")
            signingConfig signingConfigs.config
        
        staging 
            debuggable true
            applicationIdSuffix ".staging"
            buildConfigField("String", "SERVER_URL", "\"$api_base_url$api_ext_staging\"")
            signingConfig signingConfigs.config
        
        debug 
            debuggable true
            applicationIdSuffix ".debug"
            buildConfigField("String", "SERVER_URL", "\"$api_base_url$api_ext_dev\"")
            signingConfig signingConfigs.config
        
    
    compileOptions 
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    
    lintOptions 
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    


repositories 
    maven  url 'https://maven.fabric.io/public' 


apollo 
    customTypeMapping = ["Datetime": "java.lang.String"]
    customTypeMapping = ["Currency": "java.lang.String"]
    useSemanticNaming = false


dependencies 
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    // android ui and support versions
    implementation(
            "androidx.appcompat:appcompat:$appcompat_version",
            "androidx.constraintlayout:constraintlayout:$constraintlayout_version",
            "com.google.android.material:material:$material_design_components_version"
    )

    compileOnly group: "javax.annotation", name: "javax.annotation-api", version: "1.3.2"
    compileOnly group: "org.jetbrains", name: "annotations", version: "13.0"

    implementation(
            "androidx.core:core-ktx:$ktx_version",
            "androidx.fragment:fragment-ktx:$ktx_version",
            "android.arch.navigation:navigation-fragment-ktx:$nav_version",
            "android.arch.navigation:navigation-ui-ktx:$nav_version"
    )
    implementation "android.arch.navigation:navigation-fragment:$nav_version"
    // use -ktx for Kotlin
    implementation "android.arch.navigation:navigation-ui:$nav_version"
    // use -ktx for Kotlin
    implementation(
            "com.mikepenz:fastadapter:$fast_adapter_version",
            "com.mikepenz:fastadapter-commons:$fast_adapter_version",
            "com.mikepenz:fastadapter-extensions-expandable:$fast_adapter_version",
            "com.mikepenz:fastadapter-extensions:$fast_adapter_version",
            "com.mikepenz:materialize:$materialize_version"
    )

    // firebase
    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'

    // data and api
    implementation(
            "com.apollographql.apollo:apollo-runtime:$apollo_version",
            "com.apollographql.apollo:apollo-http-cache:$apollo_version"
    )
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_interceptor_version"
    // rx
    implementation(
            "io.reactivex.rxjava2:rxandroid:$rx_android_version",
            "io.reactivex.rxjava2:rxjava:$rx_java_version",
            "com.apollographql.apollo:apollo-rx2-support:$apollo_version"

    )

    implementation "de.hdodenhof:circleimageview:$circle_imageview_version"

    // koin di
    implementation(
            "org.koin:koin-android:$koin_version",
            "org.koin:koin-androidx-scope:$koin_version",
            "org.koin:koin-androidx-viewmodel:$koin_version"
    )
    // rx android networking
    implementation(
            "com.amitshekhar.android:rx2-android-networking:$afn_version",
            "com.github.prashantsolanki3:Secure-Pref-Manager:$secure_prefs_vresion"
    )

    //Beta by Crashlytics
    compile('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') 
        transitive = true;
    

    implementation 'com.jakewharton.timber:timber:4.7.1'

    implementation "com.google.maps.android:android-maps-utils:0.5"
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-places:17.0.0'
    implementation 'com.google.android.libraries.places:places:1.1.0'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    testImplementation "junit:junit:$junit_version"
    androidTestImplementation("androidx.test:runner:$test_runner_version",
            "androidx.test.espresso:espresso-core:$espresso_test_version"
    )

    //Glide
    implementation "com.github.bumptech.glide:glide:$glide_version"
    annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"

    //Permission Manager
    implementation 'com.github.florent37:runtime-permission-kotlin:1.1.0'

    //Notification banner
    implementation 'com.github.shasin89:NotificationBanner:1.1.0'

    //Loading spinner
    implementation 'com.github.ybq:Android-SpinKit:1.2.0'

    //Circle image view
    implementation 'de.hdodenhof:circleimageview:3.0.0'

    //helpers for Android SDK
    implementation "org.jetbrains.anko:anko:$anko_version"

    //date helper
    implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'

    //Picasso
    implementation 'com.squareup.picasso:picasso:2.71828'

    //EventBus
    implementation 'org.greenrobot:eventbus:3.1.1'

    //Round corner progress bar
    implementation 'com.akexorcist:RoundCornerProgressBar:2.0.3'

    //Expandable RecycleView
    implementation 'com.thoughtbot:expandablerecyclerview:1.3'

    //OneSignal
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'

    implementation "joda-time:joda-time:$jodatime_version"

    implementation 'com.github.drawers:SpinnerDatePicker:2.0.1'

    //Adjust
    implementation 'com.adjust.sdk:adjust-android:4.18.0'
    implementation 'com.android.installreferrer:installreferrer:1.0'
//    implementation 'com.adjust.sdk:adjust-android-webbridge:4.18.0' if user Adjust with webview

    testImplementation 'org.koin:koin-test:1.0.1'
    debugImplementation 'com.readystatesoftware.chuck:library:1.1.0'
    stagingImplementation 'com.readystatesoftware.chuck:library:1.1.0'
    releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0'


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

【问题讨论】:

【参考方案1】:

如果你在项目 build.gradle 中声明如下

maven  url "https://jitpack.io" 

试着换成

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

【讨论】:

【参考方案2】:

您必须检查您的互联网连接并在设置中禁用 gradle 离线模式 之后做: 文件 > 使缓存无效并重新启动。 并尝试同步应用!

【讨论】:

我试过无效重启,未勾选gradle离线模式 我认为服务器已关闭并注意到此错误。无法解析 com.google.android.gms:play-services-base:[15.0.0,16.0.0)。要求:项目:app > com.google.android.gms:play-services-location:15.0.0 > 无法列出 com.google.android.gms:play-services-base 的版本。 > 无法从 jitpack.io/com/google/android/gms/play-services-base/… 加载 Maven 元数据。> 无法获取资源“jitpack.io/com/google/android/gms/play-services-base/…”。收到状态码 403

以上是关于Android Studio 3.5 错误:无法解析“:app@debug/compileClasspath”的依赖关系的主要内容,如果未能解决你的问题,请参考以下文章

更新 Android Studio 3.5 获得 proguard 警告

Android Studio 3.5导入AOSP编译的classes.jar

[Android Studio 3.5为每个调试会话进行gradle构建

Android Studio 3.5 原因:buildOutput.apkData 不能为空 Clean & Rebuild 已经尝试过

Android Studio拒绝在我的手机上构建和安装任何应用程序

安装失败,原因是:'null' - Android Studio 3.5