1

I'm trying to configure Android Studio on a totally offline Windows PC , but got the error log :

Could not download gradle.jar(com.android.tools.build:gradle:3.1.0):No cached version available for offline mode

I google a lot for my question , most answers just disable offline mode , then download the Android Plugin for Gradle.

But I can't do it , my PC can't connect to network, is there any way to download the plugin independently and apply to Android Studio ? Or copy some files from another PC to mine ?

About this link : How to setup Android Studio to work completely offline?

This link does not help , most answers just enable offline mode , the accepted answer download a zip (I'm not sure is it a gradle.zip or an android-plugin-for-gradle.zip) and paste to ~/.gradle , but I had try to copy the ~/.gradle directory to my PC and did not help.

Archer c
  • 11
  • 3
  • [This](https://stackoverflow.com/questions/18158034/how-to-setup-android-studio-to-work-completely-offline) did not help ? – Arthur Attout Apr 09 '18 at 08:44
  • Possible duplicate of [How to setup Android Studio to work completely offline?](https://stackoverflow.com/questions/18158034/how-to-setup-android-studio-to-work-completely-offline) – TessavWalstijn Apr 09 '18 at 08:52
  • Gradle and maven requires an internet connection - while you can work around it it definitely is a huge amount of constant work to do so. – Xaver Kapeller Apr 09 '18 at 09:11
  • And btw you require an internet connection in the first place to work around it so either way you are going to have to get access to the internet somewhere somehow. – Xaver Kapeller Apr 09 '18 at 09:13
  • My Project dependent on jar and aar , so I only need a way to apply the Android Plugin for Gradle to make Android Studio work – Archer c Apr 09 '18 at 09:18

1 Answers1

0

Finally I work out a way to fix my problem , the simplest way is just copy directory m2repository from a PC which has android plugin for gradle files to offline PC , the path is {Android Studio Installation Directory}/gradle/m2repository , in my case , I check m2repository/com/android/tools/build for the the plugin files.

After the copy , I custom a local maven repository in Project build.gradle file's buildscript block like this :

buildscript {

  repositories {
        google()
        jcenter()
        maven {
            //Your m2repository path in offline PC , I overwrite my Offline PC's Android Studio's m2repository
            url 'D:/AS3.0/android-studio/gradle/m2repository'
        }
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:3.1.0'
  }
}

If you overwrite the m2repository directory too , you can comment the maven repository after the first build.

PS : Maybe the file is still in gradle cache (~/.gradle/cache) , so you can not find in the m2repository , and maybe not just a plugin file , you may want all dependencies jar files but not want do the copy actions , you can take a look at here

https://discuss.gradle.org/t/need-a-gradle-task-to-copy-all-dependencies-to-a-local-maven-repo/13397

I'm still working on it , and if I done this and have time , I will explain in detail.

Archer c
  • 11
  • 3