Gradle fails to resolve dependencies in Android Studio

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

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> 

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

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 

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.

回答1:

A similar problem here, and when I choose Build -> Clean Project there is a "peer not authenticated" error.

solved by using "http://jcenter.bintray.com/" instead of "https://jcenter.bintray.com/"

repositories {     jcenter({url "http://jcenter.bintray.com/"}) } 

hope this work for you.



回答2:

I had a similar problem with a library on github, which stated to install it as:

dependencies {     compile 'com.github.chrisbanes.photoview:library:1.2.4' } 

This workaround seem to work, although it's suboptimal because it doesn't fetch a specific version and leads to Android Studio warnings:

dependencies {     compile 'com.github.chrisbanes.photoview:library:+' } 


回答3:

Rather late but probably your gradle works in offline mode. Go to File->Settings->Gradle and uncheck the offline mode. Then try to refresh gradle and it should work



回答4:

Top build.gradle:

buildscript {     repositories {         jcenter()     }      dependencies {         classpath 'com.android.tools.build:gradle:1.1.3'     } } 

App build.gradle:

apply plugin: 'com.android.application'  android {     compileSdkVersion 22     buildToolsVersion "22.0.1"      defaultConfig {         applicationId "nl.timmevandermeer.cargoapp"         minSdkVersion 19         targetSdkVersion 22         versionCode 1         versionName "1.0"     }      buildTypes {         release {             minifyEnabled false             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'         }     } }  dependencies {      // compile fileTree(dir: 'libs', include: ['*.jar']) // <-- use gradle depedencies      compile 'com.android.support:appcompat-v7:22.0.0' // <-- brings in v4     // compile 'com.google.android.gms:play-services:7.0.0' // <-- will cause MultiDex exception, you need to choose which ones you want     // compile 'org.json:json:20141113' // <-- android comes with org.json } 

Multi-Dex Issue:

compile 'com.google.android.gms:play-services:7.0.0' is too big and should not be used directly. Please choose the modules you want here: http://developer.android.com/google/play-services/setup.html



回答5:

I am behind a corporate firewall. I had my http settings set, but not my https settings. So, I added the following to my gradle.properties file:

systemProp.https.proxyPassword=... systemProp.https.proxyHost=... systemProp.https.nonProxyHosts=... systemProp.https.proxyUser=... systemProp.https.proxyPort=... 


回答6:

Tested in UBUNTU - 14.04 ,

>delete .androidstudio1.2 , .gradle , .android  , Android studio project from home directory  > Launch using studio.sh >close the dialogue letting you choose new or old setting , just close it using that "x " button  > then it will set up an virtual nexus 5  >then there will be two errors saying problem about "sdk" and "gradle " > Caution : choose the appropriate sdk version by clicking on the link given by where the problem is shown . > close android studio  > reopen android studio  > then you will be thrown a possible  error with jdk not found . >go to file -> project structure  > give the path to jdk , in my case its "usr/local/java/jdk..." >close android studio and open again , the gradle might work well after this . 


回答7:

In my case I added this to my build.gradle (module:app):

compile 'com.github.glomadrian:velocimeterlibrary:1.1@aar'  

However, it gave me an error today. My solution is to use this instead:

compile 'com.github.glomadrian:velocimeterlibrary:+' 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!