Running Android Studio with an HTTP Proxy - gradle

I just downloaded and installed the latest version of Android Studio (3.0.1) at work to start a new tablet project. During setup it needed me to enter my proxy server information which I did. I created an empty project and it asked me to accept or reject a couple of certificates one from Google Inc (*.google.com) and another from JetBrains s.r.o. (plugins.jetbrains.com). I accepted them and they now show up in Settings -> Tools -> Server Certificates. It has been able to download a number of packages, but after everything appears to be installed I get a message "Gradle project sync failed. Basic functionality will not work properly."
There are a number of error messages that look like this:
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Could not resolve com.android.support:appcompat-v7:26.1.0.
Required by:
project :app
> Could not resolve com.android.support:appcompat-v7:26.1.0.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'.
> dl.google.com
I tried adding http and https proxy server information to the 'gradle.properties' as suggested here.
That changed the error message to this:
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Could not resolve com.android.support:appcompat-v7:26.1.0.
Required by:
project :app
> Could not resolve com.android.support:appcompat-v7:26.1.0.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> unable to find valid certification path to requested target
Further digging came up with this. Adding the URL to FireFox allows me to download the appcompat-v7-26.1.0.pom file but does not provide a "HTTPS certificate chain" to export a certificate from. I am also not sure where I am supposed to get the keytool mentioned as well.
To verify that it is the proxy setup that is causing the problem I took my laptop home. Using my home network and turning off the HTTP Proxy caused a 3rd error (connection timed out) which was fixed by clearing the certificates. So it appears that the certificates accepted in Android Studio are used by at least part of the process. Now that I am back at work everything seems to work just fine.
There must be others out there running Android Studio with an HTTP Proxy set. What is the "correct" way of fixing this?

I replaced the file
C:\Program Files\Android\Android Studio\jre\jre\lib\security>\cacerts
with the file from the jre (%JAVA_HOME%\lib\security\cacerts).
The certificates in the new cacerts file directed the android jre to go through the proxy server.

Related

Error inside docker container: Could not download spring-boot-gradle-plugin-2.5.4.jar (org.springframework.boot:spring-boot-gradle-plugin:2.5.4)

I have a spring batch application configured with docker-compose.yml. To run the project there is a run.sh file and it spinup several containers. DB container gets up and running without issues. But the container which runs the spring application fails with the below error.
Could not resolve all artifacts for configuration ':classpath'.
> Could not download spring-boot-gradle-plugin-2.5.4.jar (org.springframework.boot:spring-boot-gradle-plugin:2.5.4)
> Could not get resource 'https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/2.5.4/spring-boot-gradle-plugin-2.5.4.jar'.
> Could not GET 'https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/2.5.4/spring-boot-gradle-plugin-2.5.4.jar'.
> The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.2/userguide/build_environment.html#gradle_system_properties
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not download sonarqube-gradle-plugin-3.3.jar (org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3)
> Could not get resource 'https://plugins.gradle.org/m2/org/sonarsource/scanner/gradle/sonarqube-gradle-plugin/3.3/sonarqube-gradle-plugin-3.3.jar'.
> Could not GET 'https://plugins.gradle.org/m2/org/sonarsource/scanner/gradle/sonarqube-gradle-plugin/3.3/sonarqube-gradle-plugin-3.3.jar'.
`
But I can download those jar files from my local machine. So jars are residing in those locations. I think this container can't access the internet to download these files. There's no way to use a terminal inside the container to execute a ping command since it is exiting right after giving this error. (But I pinged google.com in DB container and it worked.So this problem is only for that particular container)
There was a workaround to add this rootProject.buildFileName = 'build.gradle.kts' in settings.gradle. But then it says Task 'bootRun' not found in root project '*'. So I think no use in this workaround and what I want to solve is the network connection issue of the container.
Issue was with this part of the error msg: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
To fix, you have to download the certificate of https://plugins.gradle.org/ and add that to cacerts file of the jdk (refer this link to see how to install the certificate)
Since I had this problem inside a container I manually replaced the cacerts file inside the container with the local cacerts file (which already contains the certificate of gradle.org).
So this whole problem is with the jdk image which was used to create the container.

Allow HTTP download in Android Studio

I am getting the following error in Android Studio:
> Could not download builder-4.1.2.jar (com.android.tools.build:builder:4.1.2)
> Could not get resource 'http://10.252.250.53:8081/lm/content/groups/public/com/android/tools/build/builder/4.1.2/builder-4.1.2.jar'.
> Could not GET 'http://10.252.250.53:8081/lm/content/groups/public/com/android/tools/build/builder/4.1.2/builder-4.1.2.jar'.
> Connect to 10.252.250.53:8081 [/10.252.250.53] failed: Connection timed out: connect
I am able to download the file from that link in a browser. So I believe the issue is that Android Studio is not allowing HTTP download.
Please guide.
The file you download is quite outdated; this is version 7.0.2 meanwhile.
Either add a self-signed SSL certificate to 10.252.250.53:8081 + local machine and define a proxy:
systemProp.https.proxyHost=10.252.250.53
systemProp.https.proxyPort=8081
Or downgrade back to Gradle < 7.0 ...if you really want to use HTTP (which is merely dead already).

Gradle SSLHandShakeException while running spring boot application

I am trying to run spring boot project with below command but I am getting ssl handshake issue.
cmd>..\gradlew bootrun
Downloading https://services.gradle.org/distributions/gradle-4.1-bin.zip
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I was referring http://www.jyothis.co.in/2011/11/12/javax-net-ssl-sslhandshakeexception/ and this is asking to install certificate from browser. I checked by copying the url in IE but it is missing certificate so I am not able to install it. Please guide me on how I could remove this error.
Thank you

Spring Tool Suite can't connect to Update site using SSL (HTTPS)

When try to connect to update sites under help->Install New Software I get:
Unable to read repository at https://dl.google.com/eclipse/plugin/4.4/content.xml.
Unable to read repository at https://dl.google.com/eclipse/plugin/4.4/content.xml.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I have tried to import the certificate into the truststore as well as set it in the sts.ini file but to no avail.
Any help greatly appreciated!
I encountered a similar issue while trying to add templates to STS (3.6.2). The issue was my organization's usage of an SSL inspection tool that presents its certificate instead of the real one (GitHub.com).
The solution was to export the SSL inspection's certificate (using IE for example) and add it to the cacerts file. Use this article for the procedure.
Then update the sts.ini file and add the following lines:
-Djavax.net.ssl.trustStore=C:\Program Files\Java\jdk1.7.0_07\jre\lib\security\cacerts
-Djava.net.ssl.trustStorePassword=changeit
Finally - restart STS.

Xcode Application Loader - communications error

Attempting to upload a binary that has passed 'validation' I get:
Communications error. Please use diagnostic mode to check connectivity. You need to have outbound access to TCP port 443
An exception has occurred: sun.security.validator.Validator.Exception: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not connect to Apple's web service
Unable to authenticate the package: 617269104.itms
Transport update failed with unexpected exception
An exception has occurred: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.ceertpath.SunCertPathBuilder\exception: unable to find valid certification path to requested target
I still have this problem despite trying all the suggestions in various similar SO threads. Running App Loader 2.9.1; Java version 7 build 1.7.0.; Yosemite beta 4; Xcode 5.1.1. Also tried all the settings in Java Control Panel General/Network Settings. All firewall ports open for outbound traffic.
Any new/further suggestions appreciated...

Resources