android studio换磁盘ADV
时间: 2025-04-02 08:04:23 浏览: 39
### 更改 Android Virtual Device (AVD) 的存储磁盘位置
在开发过程中,有时可能需要更改 AVD 存储的位置以优化性能或节省空间。以下是实现这一目标的方法:
#### 方法一:通过配置文件手动修改路径
1. **定位默认目录**
默认情况下,Android Studio 将虚拟设备数据存储在一个特定的目录下。此目录通常位于用户的主目录中,具体路径如下:
- Windows: `C:\Users\<YourUsername>\.android\avd`
- macOS/Linux: `/home/<YourUsername>/.android/avd` 或者 `~/.android/avd`
2. **创建新目录并移动现有 AVD 文件夹**
如果希望将 AVD 数据移至其他驱动器或分区,则可以先创建一个新的目标目录(例如 D:\AVDs),并将现有的 `.avd` 文件夹复制到该目录。
3. **更新配置文件中的路径**
找到对应虚拟机的配置文件 `<AVD_Name>.ini` 并打开它。编辑其中的一行内容来指定新的路径:
```properties
path=<new_absolute_path_to_avd_folder>
```
4. **验证设置**
启动 Android Emulator 验证是否成功加载自定义位置上的镜像[^1]。
#### 方法二:利用命令行工具 avdmanager 修改
也可以借助 SDK 提供的管理脚本完成迁移操作:
```bash
sdkmanager --list | grep "emulator"
```
确认安装有 emulator 组件之后运行以下指令导出再重新导入即可改变其物理地址关联关系[^2]:
```bash
avdmanager delete avd -n <existing_avd_name>
avdmanager create avd -n <new_avd_name> -k "<system_image>" -p /path/to/new/location/
```
注意替换上述模板里的占位符参数为实际使用的名称与系统映射版本号等信息。
```python
import os
from pathlib import Path
def move_avd(avd_name, new_location):
old_dir = Path.home() / ".android" / "avd" / f"{avd_name}.avd"
ini_file = Path.home() / ".android" / "avd" / f"{avd_name}.ini"
if not old_dir.exists():
raise FileNotFoundError(f"The specified AVD ({avd_name}) does not exist.")
try:
# Create the target directory structure.
new_dir = Path(new_location) / f"{avd_name}.avd"
new_dir.mkdir(parents=True, exist_ok=True)
# Move all files from original to destination folder.
for file in old_dir.iterdir():
file.rename(new_dir / file.name)
with open(ini_file, 'r') as config:
lines = config.readlines()
updated_lines = []
for line in lines:
if line.startswith('path='):
updated_lines.append(f"path={str(new_dir.resolve())}\n")
elif line.startswith('path.rel='):
continue # Remove relative paths entry since we're setting absolute ones now.
else:
updated_lines.append(line)
with open(ini_file, 'w') as config:
config.writelines(updated_lines)
except Exception as e:
print(e)
if __name__ == "__main__":
move_avd("Pixel_3a_API_30", "/mnt/disk2/android_avds/")
```
阅读全文
相关推荐
















