可以更改 Android 虚拟设备的保存位置吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2841766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Possible to change where Android Virtual Devices are saved?
提问by primehunter326
I've set up the Android SDK and Eclipse on my machine running Windows XP and AVDs (Android Virtual Devices) are saved to "Documents and Settings\user\.android" by default. Is there any way to change this behavior? I have all of the other components saved in a directory on a separate partition and would like everything to be consolidated. Obviously not a huge deal but does anyone here know a workaround for this?
我已经在运行 Windows XP 的机器上设置了 Android SDK 和 Eclipse,并且 AVD(Android 虚拟设备)默认保存到“文档和设置\用户\.android”。有什么办法可以改变这种行为吗?我将所有其他组件保存在一个单独分区的目录中,并希望将所有内容合并。显然不是什么大问题,但这里有人知道解决方法吗?
回答by wloescher
Add a new user environment variable (Windows 7):
添加新的用户环境变量(Windows 7):
- Start Menu > Control Panel > System > Advanced System Settings (on the left) > Environment Variables
- Add a new user variable (at the top) that points your home user directory:
Variable name: ANDROID_SDK_HOME
Variable value: a path to a directory of your choice
- 开始菜单>控制面板>系统>高级系统设置(左侧)>环境变量
- 添加一个指向您的主用户目录的新用户变量(在顶部):
变量名称:ANDROID_SDK_HOME
变量值: 您选择的目录的路径
AVD Manager will use this directory to save its .android
directory into it.
AVD Manager 将使用该目录将其.android
目录保存到其中。
For those who may be interested, I blogged about my first foray into Android development...
Android "Hello World": a Tale of Woe
对于那些可能感兴趣的人,我写了一篇关于我第一次涉足 Android 开发的博客......
Android“Hello World”:一个悲剧的故事
Alternatively, you can use the Rapid Environment Editorto set the environment variables.
或者,您可以使用Rapid Environment Editor设置环境变量。
回答by diyism
Modify the file "virtual_android2.2.ini" in "C:\Documents and Settings{your windows login}.android\avd\":
修改“C:\Documents and Settings{your windows login}.android\avd\”中的文件“virtual_android2.2.ini”:
target=android-8
path=E:\android_workspace\avd\virtual_android2.2.avd
And move the folder "virtual_android2.2.avd" from "C:\Documents and Settings{your windows login}.android\avd\" into "E:\android_workspace\avd\".
并将文件夹“virtual_android2.2.avd”从“C:\Documents and Settings{your windows login}.android\avd\”移动到“E:\android_workspace\avd\”。
回答by loftysnake
Go to the Android tools directory. Edit the android.bat command file. At about the end of the command file, find a line similar to
转到 Android 工具目录。编辑 android.bat 命令文件。在命令文件的末尾,找到类似于
call %java_exe% -Djava.ext.dirs=%java_ext_dirs% -Dcom.android.sdkmanager.toolsdir="%tools_dir%" -Dcom.android.sdkmanager.workdir="%work_dir%" -jar %jar_path% %*
and replace
并替换
call %java_exe%
with
和
call %java_exe% -Duser.home={your_prefer_dir}
where {your_prefer_dire} is your preferred directory without braces but add doublequotes,
其中 {your_prefer_dire} 是没有大括号但添加双引号的首选目录,
e.g.
例如
call %java_exe% -Duser.home="E:\Program Files (x86)\android-sdk-windows"
回答by Leonardo Sapuy
Based on official documentation https://developer.android.com/studio/command-line/variables.htmlyou should change ANDROID_AVD_HOMEenvironment var:
根据官方文档https://developer.android.com/studio/command-line/variables.html,您应该更改ANDROID_AVD_HOME环境变量:
Emulator Environment Variables
By default, the emulator stores configuration files under $HOME/.android/ and AVD data under $HOME/.android/avd/. You can override the defaults by setting the following environment variables. The emulator -avd command searches the avd directory in the order of the values in $ANDROID_AVD_HOME, $ANDROID_SDK_HOME/.android/avd/, and $HOME/.android/avd/. For emulator environment variable help, type emulator -help-environment at the command line. For information about emulator command-line options, see Control the Emulator from the Command Line.
- ANDROID_EMULATOR_HOME: Sets the path to the user-specific emulator configuration directory. The default location is
$ANDROID_SDK_HOME/.android/.- ANDROID_AVD_HOME: Sets the path to the directory that contains all AVD-specific files, which mostly consist of very large disk images. The default location is $ANDROID_EMULATOR_HOME/avd/. You might want to specify a new location if the default location is low on disk space.
模拟器环境变量
默认情况下,模拟器将配置文件存储在 $HOME/.android/ 下,AVD 数据存储在 $HOME/.android/avd/ 下。您可以通过设置以下环境变量来覆盖默认值。模拟器 -avd 命令按照 $ANDROID_AVD_HOME、$ANDROID_SDK_HOME/.android/avd/ 和 $HOME/.android/avd/ 中的值的顺序搜索 avd 目录。对于模拟器环境变量帮助,请在命令行中键入 emulator -help-environment。有关模拟器命令行选项的信息,请参阅从命令行控制模拟器。
- ANDROID_EMULATOR_HOME:设置用户特定模拟器配置目录的路径。默认位置是
$ANDROID_SDK_HOME/.android/。- ANDROID_AVD_HOME:设置包含所有 AVD 特定文件的目录的路径,这些文件主要由非常大的磁盘映像组成。默认位置是 $ANDROID_EMULATOR_HOME/avd/。如果默认位置磁盘空间不足,您可能需要指定一个新位置。
After change or set ANDROID_AVD_HOME you will have to move all content inside ~user/.android/avd/to your new location and change path into ini file of each emulator, just replace it with your new path
更改或设置 ANDROID_AVD_HOME 后,您必须将~user/.android/avd/ 中的所有内容移动到您的新位置并将路径更改为每个模拟器的 ini 文件,只需将其替换为您的新路径
回答by ps95
Move your .android
to wherever you want it to.
移动.android
到任何你想要的地方。
Then, create a symlink like this:
然后,创建一个像这样的符号链接:
# In your home folder
$ ln -s /path/to/.android/ .
This simply tells Linux that whenever the path ~/.android
is referenced by any application, link it to /path/to/.android
.
这只是告诉 Linux,只要路径 ~/.android
被任何应用程序引用,就将其链接到/path/to/.android
.
回答by user2511140
For Visual Studio 2017 on Windows 10
对于 Windows 10 上的 Visual Studio 2017
Copy C:\Users\YOURUSERNAME\.android
folder to (for example) E:\avd
将C:\Users\YOURUSERNAME\.android
文件夹复制到(例如)E:\avd
Open the environment variables window:
打开环境变量窗口:
- Go into Settings and click on System.
- On the left, click About and select System info at the bottom.
- In the new window, click Advanced system settings on the left.
- Click Environment Variables at the bottom of the resulting window.
- 进入设置并单击系统。
- 在左侧,单击关于并选择底部的系统信息。
- 在新窗口中,单击左侧的高级系统设置。
- 单击结果窗口底部的环境变量。
Add a new variable:
添加一个新变量:
- Variable name:
ANDROID_SDK_HOME
- Variable value: a path to a directory (e.g
E:\avd
)
- 变量名:
ANDROID_SDK_HOME
- 变量值:目录的路径(例如
E:\avd
)
Don't include .android
in the variable value.
不要包含.android
在变量值中。
Restart Visual Studio.
重新启动 Visual Studio。
For change SDK & NDK location go to:
要更改 SDK 和 NDK 位置,请转到:
Tools -> Options -> Xamarin -> Android Setting
工具 -> 选项 -> Xamarin -> Android 设置
回答by Macarse
回答by JFrostos
You can change the .ini file for the new AVD:
您可以更改新 AVD 的 .ini 文件:
target=android-7
path=C:\Users\username\.android\avd\VIRTUAL_DEVICE_NAME.avd
I don't know how to specify where the .ini file should be stored :)
我不知道如何指定 .ini 文件的存储位置:)
回答by Martin Zeitler
The environmental variable ANDROID_AVD_HOME
can be used to define the directory in which the AVD Manager shall look for AVD INI files and can therefore be used to change the location of the virtual devices;
环境变量ANDROID_AVD_HOME
可用于定义 AVD 管理器应在其中查找 AVD INI 文件的目录,因此可用于更改虚拟设备的位置;
The default value is %USERPROFILE%\.android\avd
on Windows (or ~/.android/avd
on Linux).
默认值%USERPROFILE%\.android\avd
在 Windows(或~/.android/avd
Linux)上。
One can also create a link for the whole directory %USERPROFILE%\.android
on Windows (or a sym-link for directory ~/.android
on Linux).
还可以%USERPROFILE%\.android
在 Windows 上为整个目录创建一个链接(或~/.android
在 Linux 上为目录创建一个符号链接)。
When moving AVDs, the path
entry in AVD INI file needs to be updated accordingly.
移动path
AVD 时,需要相应更新 AVD INI 文件中的条目。
回答by SR_
Please take note of the following : modifying android.bat in the Android tools directory, as suggested in a previous answer, may lead to problems.
请注意以下几点:按照之前的答案中的建议,修改 Android 工具目录中的 android.bat 可能会导致问题。
If you do so, in order to legitimately have your .android directory located to a non-default location then there may be an inconsistency between the AVDs listed by Android Studio (using "Tools > Android > AVD Manager") and the AVDs listed by sdk command line tool "android avd".
如果您这样做,为了将您的 .android 目录合法地放置到非默认位置,那么 Android Studio 列出的 AVD(使用“工具 > Android > AVD 管理器”)与列出的 AVD 之间可能存在不一致sdk 命令行工具“android avd”。
I suppose that Android Studio, with its internal AVD Manager, does not use the android.bat modified path ; it relies on the ANDROID_SDK_HOME variable to locate AVDs.
我想 Android Studio 及其内部 AVD 管理器不使用 android.bat 修改路径;它依赖于 ANDROID_SDK_HOME 变量来定位 AVD。
My own tests have shown that Android tools correctly use the ANDROID_SDK_HOME variable.
我自己的测试表明 Android 工具正确使用了 ANDROID_SDK_HOME 变量。
Therefore, there is no point, as far as I know, in modifying android.bat, and using the environment variable should be preferred.
因此,据我所知,修改android.bat并没有什么意义,使用环境变量应该是首选。