Android Studio Gradle build failed. Error:Cause: peer not authenticated-ThrowExceptions

Exception or error:

I have already created one project and gradle sync worked successfully.

When I try to create another project it fails and gives the error message that

Gradle '<ProjectName>' project refresh failed
     Error:Cause: peer not authenticated.

I have setup SDK, gradle gave gradle VM options

-Dhttp.proxyHost=<proxy.address> -Dhttp.proxyPort=<port> -Dhttp.proxyUser=<username> -Dhttp.proxyPassword=<password>

And in HTTP proxy tab also I have given the correct options.

Can anyone help me?

How to solve:

This was the solution that worked for me. Posting here in case it helps someone.

Gradle version was not correct in project build.gradle file.

I had

classpath 'com.android.tools.build:gradle:1.0.0'

but this needed to be

classpath 'com.android.tools.build:gradle:2.1.0'

Note:
This should be updated to the newest version of gradle tools which can be found here
Android Studio also recommends the latest plugin version.

###

DO NOT change your package source to http instead of https. Stop using these workarounds and fix the root cause.

Do you want to have a driveby exploit in your app? Because that’s how you get a driveby exploit in your app!

The source of this problem Certificate Authority keystore. Somehow dpkg seems to try to build the Java keystore (/etc/ssl/certs/java/cacerts) before it actually installs Java, which the the tool to build the store requires. The result is an empty store:

To fix this, properly build the keystore with all trusted CA certificates.

Run this with sudo:

sudo rm /etc/ssl/certs/java/cacerts
sudo /var/lib/dpkg/info/ca-certificates-java.postinst configure

You should see a long list of added certificates (*.pem) and finally a “done”.

Re-sync the project using gradle, and all will download. Don’t forget to turn off the http override if you’ve set it!

Source: https://justus.berlin/2015/01/connection-problems-with-ssltls-peers-in-java-on-ubuntu-server-14-12-with-fix/

###

This fixed it for me:

Open /gradle/wrapper/gradle-wrapper.properties

Change ‘https’ to ‘http’ in the distributionUrl:

distributionUrl=http\://services.gradle.org/distributions/gradle-2.1-all.zip

Then you need to sync project with gradle files

###

This error says that you’re trying to connect using HTTPS protocol, but your client unable to validate server’s certificate – usually because it is self signed.

Connect to https://jcenter.bintray.com with your browser, and check the certificate chain. The root certificate should be issued by GeoTrust Global CA. If it’s not the case, your Internet Provider or your employer perform MITM to your HTTPS connections.

If you trust them, the simple workaround will be to add those self-signed certificates into JDK’s cacerts keystore. Examples for how to do that: Windows; Linux/Mac.

###

Usually this error happens when you’re under a company proxy. My solution on MAC was this:

  1. Identify the Certificate is being used by your https connections enter image description here

  2. Open Key Chain Tools (cmd+space key chain)

  3. Identify the certificate found up and export it to certificate.cer file
  4. Open the terminal and navigate to your JAVA JRE security folder:

    cd /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/security

  5. Import the certificate with the following command:

    sudo keytool -import -alias somealias -file /PATH_TO_EXPORTED_CERTIFICATE/certificate.cer -keystore cacerts -storepass changeit

That is done. Open Android Studio and it will fix the gradle build.

###

I closed my studio and when I re-opened the project, I got a window to enter proxy information. In that, I had to check the check box which said “Enable HTTPS proxy” and that worked for me!

###

please change the gradle build tools version first. You need to update the build tools version. Still not working, create a new project and check the gradle file details. 1.5.0 is the latest version I have installed.

 classpath 'com.android.tools.build:gradle:1.5.0'

###

After meddling with it, and following Schizo’s answer (you should follow it also), and it not working. I realized Android Studio was using java-7-openjdk but I added a certificate to java-8-openjdk, so it didn’t work until I changed it to the openJDK 8 in Project Structure, so be sure that you check that also, in case it’s not working for you.

###

THis fixed it for me after wasting lot of time trying various solutions:
Check the dependencies -> classpath in build.gradle file of project

dependencies {
    classpath 'com.android.tools.build:gradle:2.10'
  }

Changed this to classpath ‘com.android.tools.build:gradle:2.0.0-rc1 in my case to fix the issue . To know the correct version to be used, made a new project and checked the build.gradle file .
Hope this helps.

###

It’s a dumb answer, but what fixed this for me was restarting Android Studio.

I was using Charles Proxy off and on, I suspect that had something to do with the cause of the error. Closed the proxy and restarted android studio, and it worked. Figured I would post because sometimes the answer is so simple we forget to even try it.

###

dependencies {
    classpath 'com.android.tools.build:gradle:1.0.1'   
}

I change classpath com.android.tools.build:gradle:1.1.3' to com.android.tools.build:gradle:1.0.0

###

There is one more small change can help you in

gradle-wrapper.properties

Change

distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

To

distributionUrl=https://services.gradle.org/distributions/gradle-2.4-all.zip

Sync the project once you did the change

###

I also faced the same issue and the problem was related to certificates.
1: So first step is go to Build-> Clean Project. It will give you the details about the error.
2: Copy URL which is failing from the stack-trace. For eg build is failed to download some file, stack-trace will have the information of the URL.
3: Open the url in a browser, if you are able to open it that means your proxy settings are fine but java is unable to trust the source to download it.
4: So you need to copy the certificate manually and put in the jre certificates. And rebuild should resolve the problem.
5: Or if you have the latest jre verison, it might solve the problem.

###

As this occurs I using Ubuntu: When I changed version on android studio 2.0 9 preview beta 1.

How do I fix my gradle.

Simply created a new project in android studio and then went in and saw build.grandle version gradle in my case:
 

 dependencies {
         classpath 'com.android.tools.build:gradle:2.0.0-beta1'
     }

and replace in my project.

I hope it helps others.

###

In my case I had to download the latest Java SDK and then change the JDK location in the project to the downloaded JDK. Apparently something was wrong with the current JDK (had some warning from my virus scanner about this)

###

In case this helps someone, I had the same issue and even though I set the proxy through the studio settings ( which adds the values of systemProp.http.proxyHost and systemProp.http.proxyHost to gradle.properties), https proxy was not set, so I added this in gradle.properties

systemProp.https.proxyHost = <your proxy host>
systemProp.https.proxyPort = <your proxy port>

and problem solved!

###

answer share from here https://stackoverflow.com/a/37962441/4030497
in case when there are some problems with internet,
try to add a line

54.231.14.232 s3.amazonaws.com

to your /etc/hosts (..\Windows\System32\drivers\etc\hosts)

###

Make sure you have specified latest gradle version in build.gradle file and latest distributionUrl in gradle-wrapper.properties file. Check network connetivity is proper or not [ Network connection should be without firewall/other settings which can stop upgrading gradle]

###

distributionUrl=http://services.gradle.org/distributions/gradle-2.1-all.zip

keep the http://

###

I have the same problem and salve it,My conduction is I define the HTTP proxy and I use agent to connect the server. Actually, you don’t need proxy to connect jcenter

###

Changing my build.gradle to shown below worked.

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

###

Update your gradle to the latest version .
It works perfectly .

distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

I hope it helps.

###

May be sometimes your app use Crashlytic bundle in your graddle
And your network cannot resolve Crashlytic library. In another way, may be others lib can cause problem. Please check your internet can access and grep those libs.

So it return an error that

“Error:Cause: peer not authenticated.”

For me, I solve this problem by comment code that evolved crashlytics lib all
and compile again —> this problem drain my working time to 4 hrs to know and clear it.

T ^ T

Wish all of us safe from this problem.

Leave a Reply

Your email address will not be published. Required fields are marked *