Keywords: Android Virtual Device | Environment Variable Configuration | AVD Storage Location
Abstract: This article provides a detailed explanation of how to customize the default storage location for Android Virtual Devices (AVDs) through environment variable configuration. Focusing on Windows system users, it covers the setup methods for ANDROID_SDK_HOME and ANDROID_AVD_HOME environment variables, including both manual configuration and tool-assisted approaches. The article also delves into AVD directory structure analysis, configuration file migration considerations, and environment variable priority relationships, offering developers a complete storage customization solution.
Overview of Android Virtual Device Storage Locations
In the Android development environment, Android Virtual Devices (AVDs) are by default stored in the .android folder within the user's home directory. For Windows XP systems, the default path is Documents and Settings\<user>\.android; for newer Windows versions, the path is typically Users\<user>\.android. This default configuration may not be ideal in certain scenarios, particularly when developers wish to consolidate all development-related files in specific partitions or directories.
Environment Variable Configuration Methods
The most effective approach to change AVD storage location is by setting specific environment variables. According to official documentation and practical experience, this primarily involves the following two environment variables:
ANDROID_SDK_HOME Environment Variable
This is the most commonly used configuration method. By setting the ANDROID_SDK_HOME environment variable, you can specify the root directory used by AVD Manager. The .android folder will be created within this directory, containing all AVD-related files.
Configuration steps for Windows 7 and later systems:
- Open Start Menu and navigate to Control Panel
- Select "System" then click "Advanced system settings" on the left
- Click "Environment Variables" in the System Properties window
- Click "New" in the User variables section
- Set variable name as
ANDROID_SDK_HOME - Set variable value to your chosen directory path
- Click "OK" to save all settings
Configuration example:
Variable name: ANDROID_SDK_HOME
Variable value: D:\Android\Development
ANDROID_AVD_HOME Environment Variable
According to Android official documentation, you can also set the ANDROID_AVD_HOME environment variable to specifically control AVD file storage location. This variable has higher priority, and when set, the emulator will preferentially use this path.
Environment variable search order:
$ANDROID_AVD_HOME$ANDROID_SDK_HOME/.android/avd/$HOME/.android/avd/
Configuration File Migration
After changing AVD storage location, if existing AVD configurations are present, file migration is necessary:
- Copy all contents from the original
.android/avd/directory to the new target location - Modify path references in each AVD's corresponding INI files
- Ensure correct file permission settings
During migration, maintain directory structure integrity, particularly the correspondence between .avd and .ini files.
Tool-Assisted Configuration
Beyond manual environment variable setting, specialized tools can simplify the configuration process. For example, Rapid Environment Editor provides a graphical interface for managing system environment variables, particularly suitable for users unfamiliar with command-line operations.
Advantages of using tools:
- Avoid errors from manual editing
- Provide variable validation functionality
- Support batch operations
- Include backup and recovery features
AVD Directory Structure Analysis
Understanding AVD directory structure facilitates better virtual device management:
.android/
├── avd/ # AVD configuration file directory
│ ├── <avd_name>.avd/ # Specific AVD data directory
│ └── <avd_name>.ini # AVD configuration file
├── cache/ # Cache files
├── ddms.cfg # DDMS configuration
└── repositories.cfg # Repository configuration
Each AVD consists of two main files: INI configuration file and data directory. The INI file contains basic AVD configuration information, while the .avd directory stores actual virtual device data, including system images, user data, etc.
Configuration Verification and Testing
After completing environment variable configuration, verification is necessary:
- Open Command Prompt, enter
echo %ANDROID_SDK_HOME%(orecho %ANDROID_AVD_HOME%) to confirm correct variable setting - Start Android Studio or AVD Manager
- Create a new AVD, check if files are generated in the specified location
- Start the emulator, verify normal functionality
If issues occur, check:
- Whether environment variable spelling is correct
- Whether the path exists and has write permissions
- Whether development environment restart is needed
Best Practice Recommendations
Based on practical development experience, the following best practices are recommended:
- Choose partitions with sufficient disk space for AVD file storage
- Maintain concise paths, avoid Chinese characters or special symbols
- Regularly backup important AVD configurations
- Use different storage locations for different projects
- Consider using SSD drives to improve emulator performance
By properly configuring AVD storage locations, developers can not only better organize their development environment but also improve development efficiency and management convenience.