按照官方文档,一步步配置好了环境变量。
android_sdk_root也配置了。也能通过android studio正常运行模拟器,但是无法通过命令行正常运行模拟器。运行时报错如下:
>emulator -avd Pixel_2_XL_API_30
emulator: ERROR: This AVD's configuration is missing a kernel file!!
emulator: ERROR: ANDROID_SDK_ROOT is defined (/Users/xxx/tools/android-sdk-macosx) but cannot find kernel file in /Users/xxx/tools/android-sdk-macosx/system-images/ sub directories
最后发现问题原因:
android sdk中,有两个emulator。
$ANDROID_SDK_ROOT/emulator下的是可以正常使用的一个
$ANDROID_SDK_ROOT/tools下的emulator不能正常使用。
使用which emulator,可以发现我们运行的是tools下的emulator。
> which emulator
<$ANDROID_SDK_ROOT>/tools/emulator
解决方案:
在path变量中,把$ANDROID_SDK_ROOT/emulator 加在$ANDROID_SDK_ROOT/tools之前可以解决这个问题,让系统调用到正确的emulator。
mac linux可以通过修改~/.bash_profile文件来做到这件事情。
stack overflow地址: