Android Studio Gradle Sync failed with company pro

2019-08-20 11:05发布

问题:

I need your help. I have to make an Android app in a company and have some problems to run and configure Android Studio. The network uses a proxy (from Zscaler) and I can't synchronize project from Gradle scripts.

The administrator have given to me the proxy address and on check connection settings, connection is successful with the 2 download domains from the build.gradle scripts. But it doesn't work on Gradle sync.

THE FOLLOWING ERRORS: With normal case on build.gradle:

  • Could not GET: "https://dl.google.com.dl/android/maven2/"
  • Could not GET: "https://jcenter.bintray.com/

With http on maven blocks: Could not GET (From jcenter binary with http)

Unable to find valid certification path.

I have also import manually certificates from the company, but it doesn't work. You can look on images to show you my configuration I have tried, and it doesn't work.

Images links here:

  1. https://ibb.co/bJxT9d
  2. https://ibb.co/e7wMUd
  3. https://ibb.co/inro9d
  4. https://ibb.co/gic6vJ
  5. https://ibb.co/eS04hy
  6. https://ibb.co/bOfLNy

Help me please, it's extremely important. I can't do the objectives otherwise.

回答1:

You need to inject your companies proxy cert into the cacerts keystore of the java attempting to download files. This may be either the OpenJDK version that is supplied with your Android Studio or the one being used by the operating system.

Keytool is located in /jre/bin

The "cacerts" file is located in /jre/lib/security

Run the following

keytool -importcert -file <path to cert> -keystore <path to cacerts>
-alias <anything>

You'll be prompted for the password, default is "changeit"

You'll then be asked if you trust the cert, type yes.



回答2:

The official solution, with keytool (3 lines to execute at least): On command line (cmd, terminal), open the directory /jre/bin, commands to write: keytool -import -alias <alias> -file <certificate_path .crt or .cer> -keystore ../jre/lib/security/cacerts

Each Java part (JRE) must to have certificates added with keytool (Java, Android Studio,...), the 2 lines must to be executed: keytool -import -alias <alias> -keystore <path_to>\system\tasks\cacerts -file <certificate_path .crt or .cer>

keytool -importkeystore -srckeystore <path_to>\system\tasks\cacerts -destkeystore "<path_to>\Java\<jre_path_name>\lib\security\cacerts"

Reboot the system after.

I remember the source: http://andreyaleev.com/2018/01/14/setup-proxy-in-android-studio/