7
votes

Can you please help me to resolve the Gradle build issue in Android 3.0 ?

I am new with Android Studio. Here are my configurations in the AS 3.0:

gradle->wrapper->gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

build.gradle dependencies (Android Plugin for Gradle):

dependencies {classpath 'com.android.tools.build:gradle:3.0.0'}

Android Studio->Settings

Android Studio Project Structure

Stacktrace from Android Studio:

D:\AppiumAutomation\MobileTest>gradlew assemble --stacktrace

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'MobileTest'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:3.0.0.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:3.0.0.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
               > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification pat
h to requested target
      > Could not resolve com.android.tools.build:gradle:3.0.0.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom'.
               > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification pat
h to requested target
3
Are you behind a proxy? If not, should you be?OneCricketeer
Hi cricket_007: No I am not behind a proxy.Jamil Rahman
Well, the error is network related. It can't get an SSL certificate for those https sitesOneCricketeer
The work station where I am trying is under a corporate network and am working remotely over VPN ('mstsc' - remote desk top connected). Does this make any difference ?Jamil Rahman

3 Answers

7
votes

It's a problem related to Android Studio 3.0 and the corporate networks. I had the same problem.

Error:Could not resolve all files for configuration ':app:debugAndroidTestRuntimeClasspath'.
    > Could not resolve com.android.support.test:runner:1.0.1.
      Required by:
          project :app
       > Could not resolve com.android.support.test:runner:1.0.1.
          > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/test/runner/1.0.1/runner-1.0.1.pom'.
             > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/support/test/runner/1.0.1/runner-1.0.1.pom'.
                > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    > Could not resolve com.android.support.test.espresso:espresso-core:3.0.1.
      Required by:
          project :app
       > Could not resolve com.android.support.test.espresso:espresso-core:3.0.1.
          > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/test/espresso/espresso-core/3.0.1/espresso-core-3.0.1.pom'.
             > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/support/test/espresso/espresso-core/3.0.1/espresso-core-3.0.1.pom'.
                > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I leave you 2 solutions:

1rst: You must add certificates manually to your java security certs (used by Android):

C:\Program Files\Android\Android Studio\jre\jre\lib\security\cacerts

SOLUTION 01 (Didn't work for me):

Go to:

C:\Program Files\Android\Android Studio\jre\jre\bin

Download the Certificate you need (just copy the URL with the problem and paste it into <remote_host_name>):

keytool -J-Dhttps.proxyHost=<proxy_hostname> -J-Dhttps.proxyPort=<proxy_port> -printcert -rfc -sslserver <remote_host_name:remote_ssl_port> > <name.cer>

Example:
C:\Program Files\Android\Android Studio\jre\jre\bin>keytool -J-Dhttps.proxyHost= proxy.mycompany.com -J-Dhttps.proxyPort=80 -printcert -rfc -sslserver https://dl.google.com/dl/android/maven2/com/android/support/test/runner/1.0.1/runner-1.0.1.pom > maven2.cer

And run the command:

keytool -import -noprompt -trustcacerts -keystore ..\lib\security\cacerts -importcert -alias <AliasName> -file <name.cer> -storepass <cacertsPassword>

If you never changed the password of cacerts the default one is changeit:

Example:
C:\Program Files\Android\Android Studio\jre\jre\bin>keytool -import -noprompt -trustcacerts -keystore ..\lib\security\cacerts -importcert -alias Maven -file maven2.cer -storepass changeit

SOLUTION 02 (Worked for me):

Download the pom entering to the URL site and store it in your local repo:

Ex:
If your missing resoruce is:
https://dl.google.com/dl/android/maven2/com/android/support/test/espresso/espresso-core/3.0.1/espresso-core-3.0.1.pom

Download it and put it in:
C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/support/test/espresso/espresso-core/3.0.1/espresso-core-3.0.1.pom
1
votes

I phase the same issue i formate the android studio and install 3.0 but issue not resolved so for resolving the issue i done following things 1.go to view and seed which files are changed. 2.the files may change after updating the plugins and platform.te 3.so you need to revert all files changes which happen due to plugin updates. enter image description here

4.Now you have to notice which files changed and go to each file local history and revert the changes for that suppose gradle file is changes so you need to right click that file and go to local history and than select show history

enter image description here

you will see two files one which will be for recent changes and one which will show you all the recenct changed files so you need to properly select the file which you have changed according time ,date

enter image description here

in above figure you can see on the left top corner their is a revert option if you click on that all chages will be reverted so click on that revert option and save the changes

enter image description here

do this with all files which is changed due to gradle plugin update and sync the project you will solve the issue .

-3
votes

Just add google() in your project level gradle file:

buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}