Android Studio Proxy Settings | Setting up a proxy in Android Studio

 Setting up a proxy in Android Studio


The other day I had to deploy Android Studio IDE on a machine with a corporate proxy. The topic is not new and has already been discussed on stackoverflow and blogs.  However, this task is not solved outright - you have to dig around. So I decided to create a step-by-step guide on how to set up an Android developer IDE in a proxy environment.


We will carry out all actions on a windows machine. For linux, the algorithm will be similar.


So, the first time you start Android Studio, it offers to configure a proxy


Click Setup Proxy , enter the proxy server address and your credentials


The proxy address can be found using the command (windows)

ipconfig / all | find / i "Dns Suffix"

Test the connection using the Check connection button on the same window. If everything is ok, let's move on.


Everything is OK, let's move on. In the proxy window that appears after starting the IDE, you need to re-register the proxy parameters for http and https

The same settings can be written in the gradle.properties file:

systemProp.http.proxyPassword = <PASSWORD>

systemProp.http.proxyHost = <PROXY_URL>

systemProp.http.proxyUser = <LOGIN>

systemProp.http.proxyPort = <PORT>

systemProp.https.proxyPassword = <PASSWORD>

systemProp.https.proxyHost = <PROXY_URL>

systemProp.https.proxyUser = <LOGIN>

systemProp.https.proxyPort = <PORT>

However, keep in mind that the IDE's proxy settings overwrite the project settings .

If you try to build the project now, then, most likely, the build will end unsuccessfully with an error


SSLHandshakeException: sun.security.validator.ValidatorException: PKIX fix

Gradle tries to reach the repository servers without having certificates. We need to add them to the repositories. To do this, first add the  following lines to  gradle.properties :

systemProp.javax.net.ssl.trustStore = <ANDROID STUDIO PATH> \\ jre \\ lib \\ security \\ cacerts

systemProp.javax.net.ssl.trustStorePassword = changeit

Here we specify the path and password to the certificate store. The default password is changeit . If you didn't change it, it remains the same.


How do you add certificates to the store?

Installing certificates

When the project starts, the IDE prompts you to accept certificates. They should be accepted, but this will not automatically help. We need to import the certificates into the IDE and JVM cacerts certificate store. To do this, follow these steps:

Download the certificate. This can be done using a browser or openssl

Import certificate to repositories using keytool

To import the certificate downloaded in step 1, on a Windows machine, you need to run a command prompt as an administrator and run:

keytool -import -alias <alias> -keystore C: \ Progra ~ 1 \ Android \ Android Studio3.0 \ jre \ jre \ lib \ security \ cacerts -file <path_to / certificate_file>

Also, you need to add this certificate to other cacerts (JVM and Android Studio):

keytool -import -alias <alias> -keystore <path_to_studio> \ .AndroidStudio3.0 \ system \ tasks \ cacerts -file <path_to / certificate_file>

 keytool -import -alias <alias> -keystore "C: \ Progra ~ 1 \ Java \ jre_V.VV \ lib \ security \ cacerts" <path_to / certificate_file>

alternatively,  instead of adding, one can copy certificates between stores using the command:

keytool -importkeystore -srckeystore <path_to_studio> \ .AndroidStudio3.0 \ system \ tasks \ cacerts -destkeystore C: \ Progra ~ 1 \ Java \ jre_V.VV \ lib \ security \ cacerts -v

 password changeit

After importing the certificates, clear the gradle cache in the C: \ Users \ <User> \ .gradle folder and reboot the system. If the IDE gives an Access denied error when trying to access the cacerts store, start Android Studio as administrator.


Launching the build ... The project is being built successfully!

If the import of certificates does not help, you can replace the download address for repositories from secure https with regular http:

jcenter {

 url "http://jcenter.bintray.com/"

 }

Git

Apart from gradle, version control issues can also arise. In the case of git, you need to add proxy parameters to the global git settings. To do this, run the command:

 git config --global http.proxy http [s]: // userName: password @ proxyaddress: port

If you get an error when trying to pull / push from / to GitLab

SSL certificate problem: self signed certificate in certificate chain

then you should run the following command from the administrator:

 git config --system http.sslCAPath <path_to_studio> /.AndroidStudio<v.No>/system/tasks/cacerts

To be able to push / pull through the Android Studio IDE, you need to specify Native in the Settings-> Version Control-> Git settings in the SSH executable item




That's all, you can work.