Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I setup Android Studio so I can compile when offline (disconnected from the internet)

I was working in androidstudio today and my builds started failing. To my surprise, I had lost my internet connection and could no longer build my code.

build.gradle file contains the following:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.3'
    }
    tasks.withType(Compile) {
        options.encoding = "UTF-8"
    }
}
apply plugin: 'android-library'

dependencies {
    compile files('libs/android-support-v4.jar')
}
...

So ... how do I reconfigure my development environment, change my build.gradle and do whatever else is necessary to allow android development offline.

Note: Question edited to remove mavenLocal() from repositories, since it was added trying to solve this problem myself

like image 479
Noah Avatar asked Oct 23 '13 01:10

Noah


People also ask

Can I run android studio without internet connection?

Yes, Android Studio is meant to be used offline, unless you are using git and committing all your code changes to git. One other scenario when you need the internet is when trying to use some external library/API using gradle.

Does Gradle require internet connection?

Gradle needs an internet connection to download the dependencies that you specify. Once it downloads everything, it can put them in memory so that you can work offline. To do this, you need to go to Files->Settings (For Mac: Android Studio-> Settings...). You can now build your project without internet.


2 Answers

Android Studio 0.4.0 added this functionality:

From the release notes:

  • Studio now supports Gradle Offline mode
like image 118
Noah Avatar answered Sep 19 '22 16:09

Noah


Google is planning to bundle gradle with Android Studio, that will provide the ability to do builds offline. However, this will not be available until v0.5.0 preview release. See here for details.

In the mean time, the current workaround is to download your own gradle libs to make any builds offline. You can do it as follows:

  1. create a library cache command: "gradle build -g ./gradle-libs". This will download all the required libraries in the folder "gradle-libs".
  2. Then, in the offline compile: "gradle build --offline -g ./gradle-libs"
like image 26
Phileo99 Avatar answered Sep 21 '22 16:09

Phileo99