How to Apply Android Plugin for Gradle to Android Studio on a TOTALLY OFFLINE PC Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to Apply Android Plugin for Gradle to Android Studio on a TOTALLY OFFLINE PC without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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.

Answer

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.

We are here to answer your question about How to Apply Android Plugin for Gradle to Android Studio on a TOTALLY OFFLINE PC - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji