Gradle 无法解析 Android Studio 中的依赖项 [英] Gradle fails to resolve dependencies in Android Studio
问题描述
每当我在 Android Studio 1.1 (OS X) 中从远程存储库 (jcenter) 添加依赖项时,同步 Gradle 时都会出现以下错误:
Whenever I add a dependency from an remote repository (jcenter) in Android Studio 1.1 (OS X) I get the following error upon syncing Gradle:
Error:(26, 13) Failed to resolve: <packagename:version>
我的app的build.gradle如下:应用插件:'com.android.application'
My app's build.gradle is as follows: apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "nl.timmevandermeer.cargoapp"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'org.json:json:20141113'
}
我尝试过更改存储库(jcenter()、mavenCentral() 等)、重新安装 Android Studio、JDK(7 和 8)、更改 Gradle 版本和 Android SDK 版本,但都没有奏效.运行 ./gradlew build 我得到:
I have tried changing repositories (jcenter(), mavenCentral(), etc.), reinstalling Android Studio, JDK (7 and 8), changing Gradle version and Android SDK version, none of which worked. Upon running ./gradlew build I get:
Could not resolve com.android.tools.build:gradle:1.1.0.
13:48:04.914 [ERROR] [org.gradle.BuildExceptionReporter] Required by:
13:48:04.915 [ERROR] [org.gradle.BuildExceptionReporter] :CargoApp:unspecified
13:48:04.932 [ERROR] [org.gradle.BuildExceptionReporter] >
org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
这也是我在其他情况下遇到的错误,例如在尝试使用 Intellij Idea 而不是 Android Studio 时.运行没有依赖项的应用程序确实有效.
This is an error I get in other cases as well, for example when trying to use Intellij Idea instead of Android Studio. Running the app without the dependency does work though.
推荐答案
这里有类似的问题,当我选择 Build -> Clean Project存在对等方未通过身份验证"错误.
A similar problem here, and when I choose Build -> Clean Project there is a "peer not authenticated" error.
通过使用 "http://jcenter.bintray.com/" 而不是 "https://jcenter.bintray.com/"
solved by using "http://jcenter.bintray.com/" instead of "https://jcenter.bintray.com/"
repositories {
jcenter({url "http://jcenter.bintray.com/"})
}
希望这对你有用.
这篇关于Gradle 无法解析 Android Studio 中的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!