Relocating SDK and Gradle Directories For Better Usage of Android Studio

Morteza Moradi
2 min readSep 22, 2023

Navigating the realm of Android development presents a myriad of challenges, not the least of which is the looming issue of storage. Three pivotal elements — the Android SDK Root, SDK HOME, and Gradle Home — are notorious for their appetite for disk space, particularly when housed on the default primary drive. This piece will delve into these storage-intensive components, elucidating their standard resting places and offering adept methods to curtail their spatial demands.1. Android SDK: The Core of Android Development

1. Android SDK: The Core of Android Development

The Problem: Over time, as you download additional tools, libraries, and system images, the Android SDK directory can swell, monopolizing valuable storage space.

Default Location: C:\Users\<Username>\AppData\Local\Android\Sdk

The Solution: Transfer the Sdk folder to another drive, for instance: D:\NewPath\Android\Sdk

Upon reopening Android Studio, it not detect the SDK at the old location. so how we give new address: Open the application. If a project loads up, you might see an error indicating that the SDK location is not set or cannot be found.

  • Access the SDK Manager:
  • Click on File in the top menu.
  • Choose Settings (or Preferences on macOS).
  • In the left pane, under Appearance & Behavior, click on System Settings.
  • Now, select Android SDK.
  • At the top of the right pane, you’ll see Android SDK Location.
  • Click on the “Edit” button or the folder icon next to the current path.
  • In the dialog that appears, navigate to the new location where you’ve moved your Android SDK.
  • Select the root directory of the moved SDK, then click OK.
  • Click on Apply at the bottom of the Settings/Preferences window.
  • Finish by clicking OK.

2. SDK HOME: Where Configurations Reside

The Problem: The ANDROID_SDK_HOME directory holds configurations, such as AVD data for emulators. This directory expands when new emulator configurations are saved or other user-specific configurations pile up.

lacking sufficient space here impedes the ability to run Android emulators

Default Location: C:\Users\<Username>\.android

The Solution: Relocate the .android folder to a desired location, say, D:\NewPath\.android.

Ensure Android Studio and any running emulators are closed before proceeding.

  • Identify your current SDK directory, typically C:\Users\<Username>\AppData\Local\Android\Sdk.
  • Transfer the entire Sdk folder to an alternative location, such as D:\NewPath\Android\Sdk.
  • Update the ANDROID_SDK_HOME environment variable:
  • Right-click on This PC > Properties > Advanced system settings > Environment Variables.
  • Under User variables, click New.
  • Variable name: ANDROID_SDK_HOME
  • Variable value: D:\NewPath\Android (This points to the directory that houses the Sdk folder.)

3. Gradle: The Powerhouse of Builds

The Problem: Gradle, the backbone of Android’s build system, caches dependencies. As you incorporate more libraries and components into your apps, these caches burgeon, eating up more space.

Default Location: C:\Users\<Username>\.gradle

The Solution: Migrate the .gradle directory to a more spacious location, e.g., D:\NewPath\.gradle.

Discover your Gradle directory, usually in C:\Users\<Username>\.gradle.

  • Move the .gradle folder to your preferred spot, e.g., D:\NewPath\.gradle.
  • Adjust the GRADLE_HOME environment variable:
  • Within the Environment Variables window:
  • Variable name: GRADLE_HOME
  • Variable value: D:\NewPath\.gradle.

--

--