Android studio - gradle无法解析依赖项

问题描述 投票:5回答:7

我在我的系统中安装了Android Studio版本2.1.2,如果我在Gradle文件中添加任何依赖项,那么I get failed to resolve error

It happen the all the libraries likes Picasso not only for Junit

所以我尝试在gradle.properties文件中添加代理设置

systemProp.http.proxyHost=http://xxxx/xxx
systemProp.http.proxyPort=80
systemProp.https.proxyHost=http://xxxx/xxx
systemProp.https.proxyPort=80

但是我收到以下错误:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not resolve junit:junit:4.12.
     Required by:
         MyApplication2:app:unspecified
      > Could not resolve junit:junit:4.12.
         > Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
            > Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pom'.
               > http://xxxx/xxx

如何解决这个问题,请帮忙。

build.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.example.muraliathmarao.myapplication"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}
android android-studio proxy android-gradle android-studio-2.1
7个回答
4
投票

您需要在main build.gradle的末尾添加一个部分allprojects,它定义项目模块的存储库:

allprojects {
repositories {
    jcenter()
  }
}

这是build.gradle(项目)

buildscript {
 repositories {
    jcenter()
    mavenCentral()
  }

  dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
       // NOTE: Do not place your application dependencies here; they belong
       // in the individual module build.gradle files
   }
 }

allprojects {
    repositories {
       jcenter()
       mavenCentral()
 } 
}

2
投票

您应该更新您的Android Repository do: 1.打开SDK Manager 2.Android支持库 3.安装包


1
投票

我在封闭的网络下,它不允许让Gradle库下载

如果您处于一个完全封闭的网络(根本没有互联网访问),那么在本地网络中拥有一个依赖性的中央内部存储库是很常见的,所有内部用户都可以从中获取依赖关系。此本地存储库需要复制您从外部站点/存储库下载的所有内容。例如,您必须从某个地方获得Android Studio安装和Android SDK依赖项。此外,Android SDK会定期收到更新 - 您在运行Android SDK管理器时是否看到了更新?

即使您是唯一的开发人员,设置您自己的本地Maven仓库以保留所有依赖项可能也很有用 - 这需要可以从您正在构建的计算机上访问(可能只在您的开发计算机上) 。见https://maven.apache.org/guides/introduction/introduction-to-repositories.html#Internal_Repositories。然后,您需要使用所需的依赖项添加到本地存储库 - 当然,这取决于您如何在封闭网络上获得任何类型的外部文件(例如,首先是您的Android Studio或Android SDK依赖项) )。


1
投票

可能存在以下任何一个问题,

  1. 首先检查存储库链接是accessible or not;通过浏览器。 (如果您无法访问该链接;请联系您的网络基础架构团队)
  2. 如果链接可以在浏览器中访问;然后问题是你的gradle configuration。确保您的根gradle文件中有以下条目。
buildscript {
      repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'>     
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    } 
} 

allprojects {
    repositories {
        jcenter()
    } 
}

1
投票

请检查build.gradle中的“buildToolsVersion”。请确保您的sdk文件已更新。否则,在build.gradle文件中将buildToolVersion从当前的'24 .0.0'更改为'23 .0.1'或更少


0
投票
allprojects {
    repositories {
       jcenter()
       mavenCentral()
       google() 
 } 
}

对我有帮助。 google()是那里的关键改进,因为所需的依赖关系是在google repo中。


-1
投票

它没有用,因为我在一个封闭的网络上,它不允许让Gradle库下载,我使用的是jar文件。

© www.soinside.com 2019 - 2024. All rights reserved.