10

I am trying to build a project in Android Studio, and Android's default build tool, Gradle, ALWAYS gives me an error when it attempts to build my project. The following is the result of using the "gradlew build" command:

FAILURE: Build failed with an exception.

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

I have tried using an http proxy, vpn, turning off my firewall, deleting the cache in the .gradle foler, and even completely reinstalling Android Studio, but nothing seems to be working.

I am new to Android development, so any information is appreciated!

Here is the error when the proxy is implemented:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'MyFirstApp'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:2.1.3.
     Required by:
         :MyFirstApp:unspecified
      > Could not resolve com.android.tools.build:gradle:2.1.3.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/
gradle/2.1.3/gradle-2.1.3.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle
/2.1.3/gradle-2.1.3.pom'.
               > Remote host closed connection during handshake

I was able to add the HTTPS certificate to the keystore for jcenter.bintray.com, but now I am getting a JVM error whenever I start android studio: Android Studio JVM Error

I have checked my environment variables, tried changing them, and the error persists. My java environment variables are set as follows:

User Variables:
    PATH: %JAVA_HOME%\bin
    JAVA_HOME: C:\Program Files\Java\jdk1.8.0_101

System Variables:
    CLASSPATH: C:\Program Files\Java\jre1.8.0_101
    JAVA_HOME: C:\Program Files\Java\jdk1.8.0_101\bin

EDIT: After setting my Java home path in the gradle.properties file, I am now getting a different error when I attempt to build my project.

Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip

Exception in thread "main" java.net.SocketException: Software caused connection abort: recv failed

EDIT: I just wanted to let everyone know that I figured it out! Apparently my parents put some insanely powerful parental control software on my computer a few years ago and I forgot it was there. After uninstalling, Android Studio now works flawlessly. The software basically blocked all unknown traffic coming in and out of most of the ports. Anyway, thank you to everyone for the help. I can finally start developing!

Jack Scott
  • 358
  • 1
  • 4
  • 13
  • Have you tried the [methods described here](https://stackoverflow.com/questions/24459182/set-up-http-proxy-in-android-studio)? – Ken Y-N Sep 05 '16 at 02:25
  • I have. I have actually been on that page numerous times hoping that it would fix my problem. When I implement the proxy, the error changes to "Remote host closed connection during handshake." – Jack Scott Sep 05 '16 at 02:35

5 Answers5

5

Try setting both http and https as shown below

gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8080 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8144

EDIT1 :

Gradle is trying to download jars from https repo "https://jcenter.bintray.com" but java does not have client certificates. Follow below steps to import client certificates

Step 1 : Download Client Certificate

a)  Open https://jcenter.bintray.com URL in the browser (i.e firefox)
b) Click on the lock icon right to the URL bar
c) Server URL is shown , click to get right arrow and then on "more information"
d) Pop-up is opened to view the certificate of the Server.
e) click on the "View Certificate", In "details" table export to a file CERT_FILE_NAME.crt

Step 2 : Import the client certificate to JDK which Gradle is using

keytool -import -noprompt -trustcacerts -alias "clojars.org" -file C:\CERT_FILE_NAME.crt -keystore C:\java\jre\lib\security\cacerts -storepass "changeit"
ravthiru
  • 8,878
  • 2
  • 43
  • 52
  • The error still persists, but it reads "Remote host closed connection during handshake." – Jack Scott Sep 05 '16 at 02:44
  • Issue might be because of certificates, you need to install certificates from https://jcenter.bintray.com into your local store and then pass the store to the gradle – ravthiru Sep 05 '16 at 03:41
  • The certificate was added to the keystore, but now I get a JVM error whenever I try to open android studio. I will post details in my question. – Jack Scott Sep 05 '16 at 17:26
  • On windows to check if Java home properly setup use , "echo %JAVA_HOME%" and "java -version" – ravthiru Sep 06 '16 at 01:35
  • Thanks again for the help. After deleting the .gradle and .android folders, I was able to get Android Studio back up and running. As I said before, the certificate has been added to the keystore, but I'm still getting the same error as before. Is there anything I need to put in my gradle files to make sure that gradle recognizes the certificate? – Jack Scott Sep 07 '16 at 14:05
  • If you have multiple installations on JAVA , check which java your gradle is using and you can configure In gradle.properties in the .gradle directory of your home, set org.gradle.java.home=/JDK-PATH – ravthiru Sep 07 '16 at 23:37
  • Alright, so I added the path to my java home in the gradle.properties file, and now gradle gives me an error when trying to download from the gradle website. See my edit above for details. – Jack Scott Sep 08 '16 at 01:04
  • Is there any issue with you network ? ar you ableto download from the browser – ravthiru Sep 09 '16 at 11:34
  • keytool error: java.lang.Exception: Keystore file exists, but is empty: C:\Program Files\Android\Android Studio\jre\lib\security\cacerts – AmiNadimi Mar 15 '18 at 17:23
4

If you behind a proxy, you must set proxy for Gradle separately because Gradle doesn't use AndroidStudio's proxy settings:

open gradle.properties and add the following lines, change ip addr to your proxy's ip.

systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyPort=7070
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=7070
Ted
  • 1,481
  • 1
  • 17
  • 18
2

I just wanted to let everyone know that I figured it out! Apparently my parents put some insanely powerful parental control software on my computer a few years ago and I forgot it was there. After uninstalling, Android Studio now works flawlessly. The software basically blocked all unknown traffic coming in and out of most of the ports. Anyway, thank you to everyone for the help. I can finally start developing!

Jack Scott
  • 358
  • 1
  • 4
  • 13
  • I had a similar solution: the Android Emulator itself was creating its own proxy via Emulator > Settings > Proxy tab. – seenickcode May 22 '18 at 03:25
2

I met this problem because i was in China. i set a wrong proxy for my AndroidStudio.it works when i delete my proxy in config file gradle.properties located in gradle directory. Hope this can help you!

systemProp.https.proxyPort=10808

systemProp.http.proxyHost=127.0.0.1

systemProp.https.proxyHost=127.0.0.1

systemProp.http.proxyPort=10808

Comment or delete above lines!

Community
  • 1
  • 1
Cyrus
  • 8,995
  • 9
  • 31
  • 58
0

Other than adding the certificate of https://jcenter.bintray.com/ to your key store, can you also check if there is a parent certificate for https://jcenter.bintray.com/. If so, you may need to add that certificate as well in the keystore.

SaAn
  • 442
  • 6
  • 22