25 C
December 17, 2018

Android Gradle Settings if you are behind a network proxy

If you are behind a proxy, often times you would end up in following errors when trying to download dependencies through gradle. This is quite common in workplace internet.

Following is a consolidated list of issues i faced and hacks/solutions i use to solve them.

1. Unrecognized SSL message, plaintext connection?

Seen this error before? I don’t know the exact reasons. But its something to do with certificates and secure connections. The hack is to change occurrences of “https” to “http” in gradle files.

Go to project’s build.gradle and make following changes.


google() to maven { url 'http://maven.google.com/' }
mavenCentral() to maven { url 'http://jcenter.bintray.com' }

Now its should look like this

repositories {
    maven { url 'http://maven.google.com/' }
    maven { url 'http://jcenter.bintray.com' }

Go to cradle-wrapper.properties file and edit ‘https’ to ‘http’ there too. Should look like this after the change.


2. SocketTimeOut Exception after adding a new dependency in build.gradle

You may still experience timeout exception even after all the steps described above is fulfilled.  Add the following lines in gradle.properties file.



This will make sure proper credentials are passed when requesting the url through proxy.

3. Fetching dependency from https only repository

In issue 1, changing from “https” to “http” worked just because those repositories support both https and http connection. What if you have to download dependencies from a third party repository which supports only ‘https’ connection? In that case Steps described above is not going to solve the problem. 

Use below steps to solve this problem.

  1. Download the files(aar, sources.jar, pem etc) locally on computer.
  2. Copy files to <Android_Sdk_Path>/extras/android/m2repository/. Maintain same package structure as in web repository. /Library/Android/sdk/extras/android/m2repository/com/example/sample/1.3.1/sample.aar
  3. Modify project’s build.gradle to include this local repository (mavenLocal()).

Modified build.gradle should look like this.

repositories {
    maven { url
‘http://maven.google.com/’ }
    maven { url
‘http://jcenter.bintray.com’ }

Related posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.