[Labs] Mencoba Android Studio Offline Build di Linux Mint 19.3

Fitur ini cukup membantu karena proses build online bisa memakan data sampai puluhan MB untuk sekali proses run. Sedangkan fitur build offline ini bisa dilakukan tanpa harus tergantung dengan koneksi internet. CMIIW.

Tentunya kemudahan ini perlu di tebus dengan trade-off yang lumayan, yaitu paket offline yang ukurannya cukup besar (2GB lebih). Bisa di simak sendiri caranya di sini:

https://developer.android.com/studio/intro/studio-config#offline

Download semua dependensi offline dan ikuti panduan sampai selesai. Untuk panduan yang sifatnya opsional, penulis tidak menggunakannya.

Download and unzip offline components

After you have downloaded the offline components, unzip their contents into the following directory, which you might need to create if it doesn’t already exist:

  • On Windows: %USER_HOME%/.android/manual-offline-m2/
  • On macOS and Linux: ~/.android/manual-offline-m2/

To update the offline components, proceed as follows:

  1. Delete the content inside the manual-offline-m2/ directory.
  2. Re-download the offline components.
  3. Unzip the contents of the ZIP files you downloaded into the manual-offline-m2/ directory.

Include offline components in your Gradle project

To tell the Android build system to use the offline components you’ve downloaded and unzipped, you need to create a script, as described below. Keep in mind, you need to create and save this script only once, even after updating your offline components.

  1. Create an empty text file with the following path and file name:
    • On Windows: %USER_HOME%/.gradle/init.d/offline.gradle
    • On macOS and Linux: ~/.gradle/init.d/offline.gradle
  2. Open the text file and include the following script:
def reposDir = new File(System.properties['user.home'], ".android/manual-offline-m2")
def repos = new ArrayList()
reposDir.eachDir {repos.add(it) }
repos.sort()

allprojects {
  buildscript {
    repositories {
      for (repo in repos) {
        maven {
          name = "injected_offline_${repo.name}"
          url = repo.toURI().toURL()
        }
      }
    }
  }
  repositories {
    for (repo in repos) {
      maven {
        name = "injected_offline_${repo.name}"
        url = repo.toURI().toURL()
      }
    }
  }
}

Save the text file.

4. (Optional) If you’d like to verify that the offline components are working as intended, remove the online repositories from your project’s build.gradle files, as shown below. After you’ve confirmed that your project builds correctly without these repositories, you can put them back into your build.gradle files.

buildscript {
    repositories {
        // Hide these repositories to test your build against
        // the offline components. You can include them again after
        // you've confirmed that your project builds ‘offline’.
        // google()
        // jcenter()
    }
    ...
}
allprojects {
    repositories {
        // google()
        // jcenter()
    }
    ...
}

Published
Categorized as labs

By Ainan

Siapalah saya... Entah kenapa aku menulis disini, aku sudah lupa. Karena semua ini pada awalnya adalah sesuatu yang tidak seharusnya menjadi seperti sekarang. Aku hanya merasa bahwa ada hal yang benar-benar ingin aku lakukan dengan menulis disini. Samar-samar aku ingat, tapi selebihnya lagi aku sudah tidak tahu itu apa dan bagaimana harus melakukannya.

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.