zhengfish
zhengfish

Reputation: 113

I failed to use gradle command line to build the android example code

I get the android example android-NetworkConnect, and I can build it within Android-Studio-1.3.

Then I want to build it with gradle command line, however I got a failed result.

/// get the example code
https://github.com/googlesamples/android-NetworkConnect

/// setting gradle
export GRADLE_HOME=/opt/gradle/gradle-2.2.1
export PATH=${PATH}:$GRADLE_HOME/bin

/// building failed
android-NetworkConnect-master $ gradle build

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':Application'.
> Could not resolve all dependencies for configuration ':Application:classpath'.
   > Could not resolve com.android.tools.build:gradle:1.2.3.
     Required by:
         android-NetworkConnect-master:Application:unspecified
      > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.2.3/gradle-1.2.3.pom'.
         > jcenter.bintray.com

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.771 secs

/// build.gradle
android-NetworkConnect-master $ cat build.gradle 
allprojects {
    repositories {
        jcenter()
    }
 }

Upvotes: 1

Views: 717

Answers (2)

zhengfish
zhengfish

Reputation: 113

It is caused by https_proxy setting. After I set the https_proxy in ~/.gradle/gradle.properties, it worked.

Here is another example for gradle.properties:

http://qiita.com/ajaxsys@github/items/fa06b4312383042beecc

Upvotes: 1

Trisha
Trisha

Reputation: 3931

Gradle is failing to get a dependency that you need ('com.android.tools.build:gradle:1.2.3') from the JCenter repo.

That dependency is available, so it's possible that for some reason the machine you're building on cannot get to the JCenter repo - does it have access to the internet? Often machines like production or QA environments do not have external access.

Alternatively you could try to connect to the Maven central repo to see if you can download from there, by updating your build file to add the Maven central repository:

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
 }

To find out more information about the failure, you can follow the advice of the error message: instead of running

gradle build

try running

gradle build --stacktrace

to see a more detailed error. This might tell you whether it's a network connection problem or not.

Upvotes: 1

Related Questions