Android studio 虚拟机问题总结一

解决 Android studio 出现“The emulator process for AVD xxx has terminated.”的错误

在CSDN、简书看了很多解答,并没有解决问题,浪费了宝贵的学习时间。

本着知其然,也要知其所以然的精神,研究了各位前辈们的方法,终于找到了问题所在,下面开始复盘。


一、问题发生

在加载虚拟机的时候显示下图

二、找出原因

android studio(以下简称ASS)的日志在

C:\Users\*你自己的用户名称*\AppData\Local\Google\AndroidStudio2021.1\log\idea.log

点开后在最下方可以看见

2022-11-04 21:11:53,987 [  29076]  INFO - manager.EmulatorProcessHandler - Emulator: F:\android\sdk\emulator\emulator.exe -netdelay none -netspeed full -avd Pixel_4_API_31 -qt-hide-window -grpc-use-token -idle-grpc-timeout 300

2022-11-04 21:11:54,034 [  29123]  INFO - manager.EmulatorProcessHandler - Emulator: PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

2022-11-04 21:11:54,034 [  29123]  INFO - manager.EmulatorProcessHandler - Emulator: INFO    | Android emulator version 31.2.9.0 (build_id 8316981) (CL:N/A)

2022-11-04 21:11:54,034 [  29123]  INFO - manager.EmulatorProcessHandler - Emulator: Process finished with exit code 1 2022-11-04 21:11:54,034 [  29123]  WARN - manager.EmulatorProcessHandler - Emulator terminated with exit code 1

其中重点的一句在

2022-11-04 21:11:54,034 [ 29123] INFO - manager.EmulatorProcessHandler - Emulator: PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

这说明了系统环境变量设置存在问题,导致了ASS在寻找ANDROID_SDK_ROOT这个变量定义的文件夹中未找到所需的东西。

这里我们需要在系统环境变量中设置ANDROID_HOMEANDROID_SDK_HOME

因为ANDROID_HOME已经被设置了,所以我没有动他。

至于为什么是SDK_HOME而不是SDK_ROOT,

我找到了ASS虚拟机 F:\android\sdk\emulator\emulator.exe

在命令行中运行即可知道。

PS C:\Users\Jan> F:\android\sdk\emulator\emulator.exe -avd foo

INFO    | Android emulator version 31.3.13.0 (build_id 9189900) (CL:N/A)

ERROR  | Unknown AVD name [foo], use -list-avds to see valid list.

ERROR  | ANDROID_SDK_HOME is defined but there is no file foo.ini in $ANDROID_SDK_HOME\avd

ERROR  | (Note: Directories are searched in the order $ANDROID_AVD_HOME, $ANDROID_SDK_HOME\avd and $HOME\.android\avd)

我用了-avd foo来看看虚拟机是怎么运行的,通过反馈可以看出emulator只能读取到$ANDROID_AVD_HOME,$ANDROID_SDK_HOME和$HOME三个变量,并没有$ANDROID_SDK_ROOT,所以这里我设置了$ANDROID_SDK_HOME。

注意这个路径中不能有中文

设置好后,我们删除之前建立的虚拟机,重启ASS。

当然,再次建立虚拟机,又一次失败了,还是一样的弹窗。


于是我用了第二个方法-------更新emulator虚拟机。

在ASS上方依次点击Tools---SDK Manager---SDK Tools

取消选择emulator然后应用,确定,即可删除虚拟机。

相同的方法再次点击Tools---SDK Manager---SDK Tools

选择emulator然后应用,确定,即可安装最新版的虚拟机。

当然依然没有打开我的虚拟手机界面,但是,在ASS的日志中,终于出现了新的信息。

2022-11-04 22:37:26,766 [ 428517] INFO - manager.EmulatorProcessHandler - Emulator: F:\android\sdk\emulator\emulator.exe -netdelay none -netspeed full -avd Pixel_2_API_27 -qt-hide-window -grpc-use-token -idle-grpc-timeout 300

2022-11-04 22:37:26,813 [ 428564]  INFO - manager.EmulatorProcessHandler - Emulator: INFO    | Android emulator version 31.3.13.0 (build_id 9189900) (CL:N/A)

2022-11-04 22:37:26,813 [ 428564]  INFO - manager.EmulatorProcessHandler - Emulator: PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

2022-11-04 22:37:26,813 [ 428564]  INFO - manager.EmulatorProcessHandler - Emulator: emulator: INFO: path_getAvdSystemPath: AVD Pixel_2_API_27 has path F:\AndroidSDK\.android\avd\Pixel_2_API_27.avd

2022-11-04 22:37:26,813 [ 428564]  INFO - manager.EmulatorProcessHandler - Emulator: emulator: INFO: path_getAvdSystemPath: trying to check whether F:\android\sdk_tools is a valid sdk root

2022-11-04 22:37:26,813 [ 428564]  INFO - manager.EmulatorProcessHandler - Emulator: emulator: WARN: path_getAvdSystemPath: F:\android\sdk_tools\system-images\android-27\google_apis_playstore\x86\ is not a valid directory.

2022-11-04 22:37:26,813 [ 428564]  INFO - manager.EmulatorProcessHandler - Emulator: emulator: WARN: path_getAvdSystemPath: emulator has searched the above paths but found no valid sdk root directory.

2022-11-04 22:37:26,813 [ 428564]  INFO - manager.EmulatorProcessHandler - Emulator: Process finished with exit code 1

2022-11-04 22:37:26,813 [ 428564]  WARN - manager.EmulatorProcessHandler - Emulator terminated with exit code 1

仔细分析一下

F:\android\sdk_tools\system-images\android-27\google_apis_playstore\x86\ is not a valid directory.

这句话前面的路径恰巧就是我ANDROID_HOME的路径,我迅速看了下这个文件夹,发现sdk_tools里面根本就没有下载的安卓SDK,我再次向ASS也确认了下。

果然ASS把SDK下载在了sdk文件夹,不是sdk_tools。

问题豁然开朗,我迅速将环境变量中的ANDROID_HOME改成了sdk文件夹的路径。

重复删除虚拟机,重启ASS的步骤。

至此我终于看到了我最喜欢的Pixel手机的桌面。

三、完结撒花


转载于:https://www.jianshu.com/p/fc278242453c

猜你喜欢

转载自blog.csdn.net/weixin_42602900/article/details/129526386