Mr. Fish Mr. Fish - 1 year ago 204
Android Question

Android Studio console build cannot reuse cached gradle dependencies

Android Studio is running on version 2.2.2 with gradle 3.2.1 and gradle plugin 2.2.2

I am working on a project migration from Eclipse ADT to Android Studio. My Android Studio project has multiple ADT projects imported as modules. Android Studio runs in offline mode, gradle sources are available locally.

Top level build.gradle

buildscript {
repositories {
jcenter ()
dependencies {
classpath ''
allprojects {
repositories {

This is an example module build.gradle

apply plugin: ''

android {
compileSdkVersion 23
buildToolsVersion "25.0.1"
defaultConfig {
applicationId ""
minSdkVersion 17
targetSdkVersion 23
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
externalNativeBuild {
ndkBuild {
path 'jni/'

dependencies {
compile ''
compile files('libs/commons-exec-1.3.jar')
compile files('libs/commons-io-2.4.jar')

Gradle sync in Android Studio works fine, but any console build with option
fails, because of missing cached repository. I can't go online to test an online sync.

I've tried different build options, defined
without success.

This is the exception

* What went wrong:
A problem occurred configuring root project 'My-Project'.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not resolve
Required by:
project :
> No cached version of available for offline mode.

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

Is it not possible to reuse the cached repository of the Android Studio gradle sync? There are so many project folders which seems to contain the cached gradle files, but which one is it? I can see
. Do I have to specify every single task on a console build?

Answer Source

I needed to get sure the path to the gradle cache has been defined and it is the same for Android Studio and the console build.

The easiest way is to define path to gradle home:

export GRADLE_USER_HOME=/path/to/gradle/local/cache

I created a dummy project on a computer with internet access, executed a gradle online sync. After that, switched into offline mode in Android Studio and executed ./gradlew --offline in the project folder. Build was successful.

Now, it is possible to create a new project still in offline mode (internet access can be switched off) and use the cached gradle build.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download