21

I am trying to build react-native android app, as a dependecy I see I have gradle, but it fails to load on build. Error message:

* What went wrong:
A problem occurred configuring root project 'MobileApp'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:1.3.1.
     Required by:
         :MobileApp:unspecified
      > Could not resolve com.android.tools.build:gradle:1.3.1.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.3.1/gradle-1.3.1.pom'.
               > Connection to https://jcenter.bintray.com refused

The issue is clear, I am sitting behind corporate proxy that blocks any HTTPSconnections like these in error. So my questions are: how to force gradle to use HTTP in loading these files? Where these properties should be put(which of gradle files, i.e. gradle.properties)?

P.S. I already have set these in gradle properties file:

systemProp.http.proxyHost= myHost
systemProp.http.proxyPort= myPort
systemProp.http.proxyUser= myUser
systemProp.http.proxyPassword= myPassword

Any links, suggestions or etc. will help a lot.

Mindaugas
  • 1,173
  • 5
  • 15
  • 31
  • 1
    Have a look here: http://stackoverflow.com/questions/25994163/could-not-resolve-all-dependencies-for-configuration-classpath. – Opal Mar 16 '16 at 07:59
  • This is the correct answer! Thanks a million, I've googled in wrong way probably, because I didn't come across this link you provided! It saved me some time! Cheers! :) – Mindaugas Mar 16 '16 at 08:27
  • You're welcome. Have you upvoted the linked question and answer? – Opal Mar 16 '16 at 08:30
  • Yea, I did. I always upvote the Q and the A that helped me. :) – Mindaugas Mar 16 '16 at 08:47
  • Great, not all of user do :/ – Opal Mar 16 '16 at 08:52
  • 1
    Yea, I know - little bit sad. Lets hope in near future it will be default behavior of an average stackoverflow user. :) – Mindaugas Mar 16 '16 at 11:45

4 Answers4

28

I had same problem and fixed it.

gradle is forced to get dependencies from jcenter through https proxy.

if you add

maven { url "http://jcenter.bintray.com" }

in your repositories instead of jcenter(), gradle sees this repository as a simple maven repository with http proxy.

your project build.gradle should be like below:

buildscript {
    repositories {
        maven { url "http://jcenter.bintray.com" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

allprojects {
    repositories {
        maven { url "http://jcenter.bintray.com" }
    }
}
Benoit Duffez
  • 11,839
  • 12
  • 77
  • 125
  • 4
    Was having an issue with HTTPS behind firewall, this fixed it. Thanks! – SacWebDeveloper Jun 13 '16 at 20:38
  • Yeeeey! After only about 2 hours my gradle build works! Thanks :) – geisterfurz007 Jan 25 '18 at 14:39
  • This no longer works since Jan 2020 as jcenter returns 403 Forbidden on HTTP requests. See https://jfrog.com/blog/secure-jcenter-with-https/ – DBPaul Aug 07 '20 at 12:53
  • @DBPaul Then what is the fix for it. I need a help. Any help is appreciated. Thanks in advance. – user7418129 May 13 '21 at 06:23
  • 1
    @ABHIMANGALMS check this: https://stackoverflow.com/questions/66651640/jcenter-deprecation-impact-on-gradle-and-android Or try `maven {url "http://jcenter.bintray.com" allowInsecureProtocol = true}` – stefan-dan Jun 24 '21 at 08:06
  • @stefan-dan Thank you very much for your response. But still, I'm not able to build the gradle. I'm trying to build https://github.com/abhimangalms/pulse-sms-android . can you please check. It would be a great help. – user7418129 Jun 25 '21 at 02:06
  • The jcenter() and bintray.com servers will be down after 2022, that's why you get the Forbiden status. It will be much harder then just changing the URL, you have to replace with something from Maven or to remove that 7 dependecies that are not available anymore. For more details check: https://blog.gradle.org/jcenter-shutdown – stefan-dan Jun 25 '21 at 07:45
11

replace jcenter() with jcenter { url "http://jcenter.bintray.com/"} in build.gradle

Sam
  • 6,215
  • 9
  • 71
  • 90
0

Try this

  • run a proxy like freegate

  • the root path project in cmd type

    gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8580

File -> Settings -> Project Settings -> Gradle -> Global Gradle Settings -> Gradle VM Options

-Dhttp.proxyHost=myProxyAddr
-Dhttp.proxyPort=myProxyPort
-Dhttp.proxyUser=myUsername
-Dhttp.proxyPassword=myPasswd 
-Dhttp.auth.ntlm.domain=myDomainName
Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
-1

Go into the gradle/wrapper folder nearby and edit the gradle-wrapper.properties

Then add in a the https to the distribution URL and it should work.

distributionUrl=https\://services.gradle.org/distributions/gradle-1.10-bin.zip
                    ^

Verify the file you are trying to grab is actually on the repo:

https://services.gradle.org/distributions/

Rerun your command to get the gradle wrapper version.

gradle wrapper
gradlew.bat wrapper -gradle-version="1.10"

Hope that helps.

phyatt
  • 18,472
  • 5
  • 61
  • 80