Android studio - gradle failed to resolve dependencies
Asked Answered
C

7

5

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'
}
Certificate answered 21/7, 2016 at 10:58 Comment(8)
Can you post your bulid.gradle?Damal
@nshmura, build.gradle added in questionCertificate
i guess you must be behind the firewall (like Zscaler). If thats so then you need to import cacert (ssl certificate) in java and restart the android studio. check this link out if it helps javarevisited.blogspot.in/2012/03/…Grafton
@Certificate Thanks. I can't find problem in build.gradle. Can you get pom file with curl? like this: curl --head https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.pomDamal
Are you connected to the internet when building your project?Singly
try to change buildToolsVersion "24.0.0" to 23.0.0Kunlun
what about classpath 'com.android.tools.build:gradle:2.1.0'Neoterize
add this in your project level gradle section task clean(type: Delete) { delete rootProject.buildDir }Neoterize
L
4

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()
 } 
}
Lambertson answered 21/7, 2016 at 11:38 Comment(5)
add this and check it repositories { mavenCentral() }Lambertson
Add this in your build.gradle dependencies section: compile 'com.squareup.picasso:picasso:2.5.1' instead of 'compile 'com.squareup.picasso:picasso:2.5.2''Lambertson
in two repository places?Certificate
yes 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() } }Lambertson
Let us continue this discussion in chat.Lambertson
C
2

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

Crustal answered 1/8, 2016 at 8:22 Comment(0)
S
1

I am under closed network, it does not allow to get Gradle library get downloaded

If you're on a completely closed network (no internet access at all), it's common to have a central in-house repository for dependencies, within the local network, where all internal users can get dependencies from. This local repository needs to replicate everything that you would download from external sites/repositories. For example, you must have got your Android Studio install and Android SDK dependencies from somewhere. Also, the Android SDK regularly receives updates - do you see updates when you run the Android SDK manager?

Even if you're the only developer, it may be useful to set up your own local Maven repo to keep all your dependencies in - this needs to be accessible from the machine you're building on (could just be on your development machine). See https://maven.apache.org/guides/introduction/introduction-to-repositories.html#Internal_Repositories. Then you need to add to your local repository with the dependencies you need - how you do this of course will depend on how you get any kind of external file onto your closed network (e.g. like your Android Studio or Android SDK dependencies in the first place).

Signify answered 1/8, 2016 at 11:59 Comment(0)
S
1

There could be any one of the following issue,

  1. First check the repository link is accessible or not; through your browser. (If you're unable to access the link; contact your network infrastructure team)

  2. If link is accessible in browser; then the issue is with your gradle configuration. Make sure you have following entries in your root gradle file.

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()
    } 
}
Sandalwood answered 1/8, 2016 at 14:30 Comment(0)
R
1

Please check your 'buildToolsVersion' in build.gradle.Please make sure that your sdk files have been updating. Otherwise change buildToolVersion from your current '24.0.0' to '23.0.1' or less in build.gradle file

Riptide answered 2/8, 2016 at 7:25 Comment(0)
B
0
allprojects {
    repositories {
       jcenter()
       mavenCentral()
       google() 
 } 
}

helped for me. google() was the key improvement there, as the desired dependencies were in the google repo.

Backchat answered 9/2, 2019 at 19:43 Comment(0)
C
-1

It wasn't working because I am on a closed network, it does not allow to get Gradle library get downloaded, I am using jar files.

Certificate answered 28/7, 2016 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.