Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio - gradle failed to resolve dependencies

I have installed Android Studio version 2.1.2 in my system and if I add any dependencies in the Gradle file then I get failed to resolve error.

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

So I tried to add proxy setting in gradle.properties file

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

but I get the following error:

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

How to resolve this issue, please help on that.

build.gradle file:

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'
}
like image 803
M.A.Murali Avatar asked Jul 21 '16 10:07

M.A.Murali


2 Answers

You need to add a section allprojects at the end of your main build.gradle that defines the repositories for the modules of your project:

allprojects {
repositories {
    jcenter()
  }
}

and this is the build.gradle (project)

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()
 } 
}
like image 147
Nikhil PV Avatar answered Sep 26 '22 07:09

Nikhil PV


You should update your Android Repository do to it:
1.Open SDK Manager
2.Android Support Repository
3.Install packages

like image 41
Brijesh Goswami Avatar answered Sep 25 '22 07:09

Brijesh Goswami