Hello, Android Studio users!

 

I had installed Android Studio 2.3 long time ago, and tried to update it to 3.0 yesterday.
Then, build was failed with the message:

"Unable to resolve dependency"

I’ve struggled with this problem and found a workaround.

On threads of Stack Overflow, it seems many developers have been caught in the same trouble.
So, I write the solutions here.

The cause of this problem

I think previous versions of Android Studio passed some properties to gradle. But the latest version not.
So, we must set some sytemProp parameters in gradle.properties file.

gradle.properties is located in
{Android Studio Project}/gradle.properties

My environments

gradle 4.1
Android Studio 3.0.1
Build #AI-171.4443003, built on November 10, 2017
JRE: 1.8.0_152-release-915-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

Error Messages 1

Logs

The below logs were shown.

 
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'.
> Connect to dl.google.com:443 [dl.google.com/172.217.26.46] failed: Connection timed out: connect
> Connection timed out: connect

Solution

The previous versions of Android Studio might pass the following Proxy setting to gradle, but the latest may not.
Settings -> Appearence & Behavior -> System Settings -> HTTP Proxy

So, you should add http and https proxy setting like this.

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

Error Messages 2

Logs

After “Error Messages 1” were solved, other error messages were shown.

 
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

Solution

Key phrases of the messages are “unable to find valid certification path” and “PKIX path building failed“.
These phrases are shown when an SSL certification file can not be found.

So, I imported some certifications into Android Studio JDK cacerts from Android Studio’s cacerts.

Android Studio’s cacerts may be located in
{your-home-directory}/.AndroidStudio3.0/system/tasks/cacerts

I used the following import command.

$ keytool -importkeystore -v -srckeystore {src cacerts} -destkeystore {dest cacerts}

Example:

$ cd {your-android-studio-directory}\jre\jre\lib\security
$ keytool -importkeystore -srckeystore {your-home-directory}\.AndroidStudio3.0\system\tasks\cacerts -destkeystore .\cacerts -v
出力先キーストアのパスワードを入力してください:
ソース・キーストアのパスワードを入力してください:
別名dl.google.comのエントリのインポートに成功しました。
別名maven.google.comのエントリのインポートに成功しました。
別名addon.xmlのエントリのインポートに成功しました。
別名sys-img.xmlのエントリのインポートに成功しました。
インポート・コマンドが完了しました: 4件のエントリのインポートが成功しました。0件のエントリのインポートが失敗したか取り消 されました
[.\cacertsを格納中]

The keytool command requires a keystore password.
The default password is “changeit

Next, add trustStore path in gradle.properties file.

systemProp.javax.net.ssl.trustStore={your-android-studio-directory}\\jre\\jre\\lib\\security\\cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit
 

I hope your problems will be resolved.