3

I have rather a curiosity than a problem which in its very own place could lead to a problem if not solved;

I've found out for building an android app you can invoke gradlew(.bat) at root dir of a project. so when I ran for instance
gradlew tasks
it generates the followings

Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip

Exception in thread "main" java.net.UnknownHostException: services.gradle.org
        at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
        at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source)
        at sun.net.NetworkClient.doConnect(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
        at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
        at org.gradle.wrapper.Download.download(Download.java:44)
        at org.gradle.wrapper.Install$1.call(Install.java:61)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

I simply can connect to internet and let it to download the necessary file,
But here my mentioned curiosity originates:
How it comes that when I build(debug) the app through android studio, android studio generates the APK with no error at all?
In android studio I defined 'local gradle distribution' to be used instead of 'default gradle wrapper' as appeared in the link below:

captured_and_std_img



Back to command-line, Afterwards I defined the environment variable GRADLE_HOME and tried one more time to build the app using gradle which is now a recognized command, as following:

gradle assembleDebug
But it also produced the followings:


Starting a Gradle Daemon, 2 incompatible Daemons could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'MyApplication2'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:3.0.1.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:3.0.1.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
               > dl.google.com
      > Could not resolve com.android.tools.build:gradle:3.0.1.
         > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
            > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.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.

* Get more help at https://help.gradle.org

BUILD FAILED in 38s



I'm not sure if assembleDebug could be used as a parameter with gradle command, I know you could use it with gradlew, but I still don't want to download the file (gradle-4.1-all.zip) and want to build the APK using 'local gradle distribution'. :))
Any possible solution would be appreciated


EDIT:
build.gradle(project) file contents:

//task wrapper(type: Wrapper) {
//  gradleVersion = '4.1'
//}

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(module):


apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:25.3.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:25.3.1'
}

2 Answers 2

1

Check your Android Studio has a proxy and check your gradle.properties has a proxy too enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

I noticed that Android Studio creates a temporary file each time I debug an app and pass that file as an argument to gradle command-line:

2022-04-03 10:37:18,658 [ thread 18] INFO - oject.common.GradleInitScripts - init script file sync.local.repo contents "allprojects {\n buildscript {\n repositories {\n maven { url 'C:\\\\Program Files\\\\Android\\\\Android Studio\\\\gradle\\\\m2repository'}\n }\n }\n repositories {\n maven { url 'C:\\\\Program Files\\\\Android\\\\Android Studio\\\\gradle\\\\m2repository'}\n }\n}\n"

the content in a normal perspective:


allprojects {
  buildscript {
    repositories {
      maven { url 'C:\\Program Files\\Android\\Android Studio\\gradle\\m2repository'}
    }
  }
  repositories {
      maven { url 'C:\\Program Files\\Android\\Android Studio\\gradle\\m2repository'}
  }
}



Passing to gradle command-line with --init-script option:

gradle --init-script path/to/file --offline assembleDebug


--init-script option prabably could be defined in gradle.properties file, I'v not tested!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.