为什么我不能添加项目依赖项?

时间:2018-10-20 09:51:40

标签: android android-studio gradle dependencies

当我开始一个新项目时,我看到有关我的依赖项的以下错误。 实际上,我正在使用VPN,但是我不知道这是什么问题?! 而且我以前没有这个问题,但是现在看到了,因为我更新了Android Studio,我应该说我搜索了很多这个问题,但是没有找到解决方案

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.google.android.gms:play-services-maps:16.0.0.
Open File
Show Details

build.gradle(Module:app):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.pasargad.test_map"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

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.android.tools.build:gradle:3.1.4'


        // 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
}

3 个答案:

答案 0 :(得分:0)

首先请确保已禁用gradle脱机工作,如下图所示。gradle offline work

现在将PC与Internet连接。然后再次同步您的项目。它应该可以解决您的问题。

答案 1 :(得分:0)

确保android studio不在离线模式下,并与互联网连接重新同步,如果所有这些都不起作用,则


1)转到文件资源管理器上的android studio文件夹或其他内容,然后转到gradle,然后查看您的gradle文件(例如,我的平均版本为 gradle-4.6-all ,然后将其删除)
2)转到gradler offilce网站并下载相同的gradle版本 gradle official site(例如gradle v4.6)
3)将其解压缩并粘贴到已删除的位置
4)重新同步互联网连接

答案 2 :(得分:0)

我找到了答案。问题是由于“ gradle.properties”文件中的代理信息,我删除了有关代理的所有行(主机,密码等)并再次同步了项目