35

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?

Jijo Thomas
  • 875
  • 1
  • 10
  • 14
  • I have changed it to distributionUrl=http://services.gradle.org/distributions/gradle-2.1-all.zip. Still not working. – Jijo Thomas Nov 10 '14 at 11:05
  • 2
    I have identified the issue. You need to check with version of "com.android.tools.build:gradle:" suits for Android studio in your installation. This issue normally happens to projects which were working fine after Android studio update. If issue exists, You can just create a sample project and can check the version of gradle installed. – Jijo Thomas Nov 03 '15 at 06:24
  • Hope you find your solution [here](http://stackoverflow.com/questions/38429550/peer-not-authenticated-error-while-building-app-in-android-studio/38456041#38456041). – krishna5688 Jul 19 '16 at 10:35

22 Answers22

40

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.

the_new_mr
  • 3,476
  • 5
  • 42
  • 57
  • Changing the classpath latest version helped me. Thank you – Akbarsha Jun 12 '15 at 06:43
  • @ the down voters. Please be aware that this answer was correct at time of writing. I've updated the answer to mention that this should be the latest gradle version. – the_new_mr Nov 26 '15 at 13:03
18

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/

SchizoDuckie
  • 9,353
  • 6
  • 33
  • 40
10

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.

Gandhi
  • 11,875
  • 4
  • 39
  • 63
Alex Lipov
  • 13,503
  • 5
  • 64
  • 87
  • It's working in gradle 1.2. with "classpath 'com.android.tools.build:gradle:0.12.2" and "distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip". I believe its not accepting with gradle 2.1 and build tools 13+ – Jijo Thomas Nov 17 '14 at 11:40
  • @JijoThomas Did you checked the certificate chain? – Alex Lipov Nov 17 '14 at 11:59
  • 3
    Adding the certificate to the JDK CA certificate store is the right way to resolve this issue. Thanks for the links! – Norman H Aug 13 '15 at 20:47
  • I've tried this first - did not worked - but than tried this: http://stackoverflow.com/a/27206173/500096 - and worked. Others solutions I suppose are just temporarily. – Paul Feb 29 '16 at 13:01
  • That works if you know your firewall/proxy spoof certificates as mine do. – Michał Fita Apr 05 '16 at 15:25
  • https://jcenter.bintray.com/ gives me error 403 Forbidden (nginx) – naXa stands with Ukraine Oct 01 '22 at 12:38
  • @naXastandswithUkraine I didn't mention to expect 200. Even if you get 403 - you should be able to inspect the certificate chain. – Alex Lipov Oct 02 '22 at 09:50
7

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.

albanx
  • 6,193
  • 9
  • 67
  • 97
5

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.

Keith
  • 547
  • 6
  • 14
  • If you are updating some components and not updating the gradle file, the error happens normally. I faced this issue multiple times and figured it out. – Jijo Thomas Jul 28 '16 at 17:49
1

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!

Surekha
  • 582
  • 1
  • 7
  • 12
1

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'
Jijo Thomas
  • 875
  • 1
  • 10
  • 14
1

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.

Community
  • 1
  • 1
Aleksandar Stefanović
  • 1,583
  • 2
  • 20
  • 36
1

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.

Vishu Gupta
  • 611
  • 5
  • 10
0
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

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

Rajeshwar
  • 1,471
  • 1
  • 12
  • 13
0

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.

AVINASH SHRIMALI
  • 580
  • 6
  • 11
0

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.

Levi Saturnino
  • 221
  • 3
  • 4
0

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)

Dominik
  • 1,703
  • 6
  • 26
  • 46
0

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!

Nonos
  • 2,450
  • 2
  • 23
  • 34
0

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)

Community
  • 1
  • 1
Serg
  • 41
  • 3
0

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]

Selvaji
  • 9
  • 2
-1
distributionUrl=http://services.gradle.org/distributions/gradle-2.1-all.zip

keep the http://

cipley
  • 1,091
  • 10
  • 15
-1

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

Patryk
  • 22,602
  • 44
  • 128
  • 244
Cuddly
  • 31
  • 4
-1

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
}
Arildo Junior
  • 796
  • 1
  • 8
  • 15
-2

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.

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
-4

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.