Emulator crashes in Android Studio due to invalid SDK root
mairs8 opened this issue · 6 comments
I am not able to run the Android Virtual Device emulator from Android Studio 2022.3.1.
The emulator crashes with message Cannot find valid sdk root path
.
The emulator appears to be looking for the sdk root in /nix/store
judging from the output of the crash log below.
what am I missing?
Steps to Reproduce
- add
android-nixpkgs
to nixos machine via home-manager module below. - launch android-studio.
- provide SDK Location: File -> Project Structure -> SDK Location -> enter
/home/$USER/Android/Sdk
. - add AVD: Tools -> Device Manager -> Create Device -> follow instructions to create Pixel_5_API_34 device.
- launch emulator.
- observe crash log output below in
/home/$USER/.cache/Google/AndroidStudio2022.3/log/idea.log
.
Failed Attempts to Fix
- make
local.properties
read only and removing sdk.path value in the file per FAQ section. - Remove "Android SDK" element from
~/.config/Google/AndroidStudio{Version}/options/jdk.table.xml
per FAQ section. - Set
ANDROID_HOME
andANDROID_SDK_HOME
environment variables to/home/$USER/Android/Sdk
via the Android Studio terminal and .bashrc.
Android Studio Crash Log
INFO - #com.android.tools.idea.devicemanager.DeviceManagerAndroidDebugBridge - []
INFO - #com.android.sdklib.internal.avd.AvdManager - /home/$USER/.android/avd/Pixel_5_API_34.avd/hardware-qemu.ini.lock not found for Pixel_5_API_34
INFO - #com.android.sdklib.internal.avd.AvdManager - /home/$USER/.android/avd/Pixel_5_API_34.avd/userdata-qemu.img.lock not found for Pixel_5_API_34
WARN - #com.android.tools.idea.avdmanager.AvdManagerConnection - Unable to determine if Pixel_5_API_34 is online, assuming it's not
INFO - Emulator: Pixel 5 API 34 - /home/$USER/Android/Sdk/emulator/emulator -netdelay none -netspeed full -avd Pixel_5_API_34 -qt-hide-window -grpc-use-token -idle-grpc-timeout 300
INFO - Emulator: Pixel 5 API 34 - Storing crashdata in: /tmp/android-$USER/emu-crash-34.1.12.db, detection enabled for process: 21252
WARN - Emulator: Pixel 5 API 34 - ANDROID_SDK_ROOT is missing.
INFO - Emulator: Pixel 5 API 34 - Android emulator version 34.1.12.0 (build_id 11146273) (CL:N/A)
INFO - Emulator: Pixel 5 API 34 - checking ANDROID_HOME for valid sdk root.
WARN - Emulator: Pixel 5 API 34 - platforms subdirectory is missing under /nix/store, please install it
INFO - Emulator: Pixel 5 API 34 - checking ANDROID_SDK_ROOT for valid sdk root.
INFO - Emulator: Pixel 5 API 34 - emulator: WARN: Cannot find valid sdk root from environment variable ANDROID_HOME nor ANDROID_SDK_ROOT,Try to infer from emulator's path
WARN - Emulator: Pixel 5 API 34 - platforms subdirectory is missing under /nix, please install it
INFO - Emulator: Pixel 5 API 34 - guessed sdk root is /nix/store
WARN - Emulator: Pixel 5 API 34 - platforms subdirectory is missing under /, please install it
INFO - Emulator: Pixel 5 API 34 - guessed sdk root /nix/store does not seem to be valid
INFO - Emulator: Pixel 5 API 34 - guessed sdk root is /nix
WARN - Emulator: Pixel 5 API 34 - invalid sdk root /
INFO - Emulator: Pixel 5 API 34 - guessed sdk root /nix does not seem to be valid
INFO - Emulator: Pixel 5 API 34 - guessed sdk root is /
INFO - Emulator: Pixel 5 API 34 - PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT
INFO - Emulator: Pixel 5 API 34 - guessed sdk root / does not seem to be valid
INFO - Emulator: Pixel 5 API 34 - emulator: WARN: Cannot find valid sdk root path.
INFO - Emulator: Pixel 5 API 34 - Process finished with exit code 1
SEVERE - Emulator: Pixel 5 API 34 - Emulator terminated with exit code 1
android-sdk.nix
{ config, pkgs, lib, android-nixpkgs, system, inputs, ... }:
{
imports = [ inputs.android-nixpkgs.hmModule ];
nixpkgs.overlays = [ inputs.android-nixpkgs.overlays.default ];
android-sdk.enable = true;
# Optional; default path is "~/.local/share/android".
android-sdk.path = "${config.home.homeDirectory}/Android/Sdk";
android-sdk.packages = sdk: with sdk; [
build-tools-34-0-0-rc3
cmdline-tools-latest
emulator
platform-tools
platforms-android-34
sources-android-34
system-images-android-34-google-apis-x86-64
];
}
@tadfisher is there any update on this? I feel like there is something obvious I'm missing given it's such a basic error but no one else has raised.
@mairs8 From your logs:
WARN - Emulator: Pixel 5 API 34 - ANDROID_SDK_ROOT is missing.
...
INFO - Emulator: Pixel 5 API 34 - checking ANDROID_HOME for valid sdk root.
...
INFO - Emulator: Pixel 5 API 34 - checking ANDROID_SDK_ROOT for valid sdk root.
...
INFO - Emulator: Pixel 5 API 34 - emulator: WARN: Cannot find valid sdk root from environment variable ANDROID_HOME nor ANDROID_SDK_ROOT,Try to infer from emulator's path
...
INFO - Emulator: Pixel 5 API 34 - PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT
@igor-ramazanov I don't think it is this. From the official android studio docs.
"ANDROID_SDK_ROOT, which also points to the SDK installation directory, is deprecated."
Also Android studio doesn't seem to respect the enviroment variables i am setting in my .bashrc
anyway.
It could depend on the shell you use to launch the app. If it's sh
, bash
or something else.
New processes won't see .bashrc
env vars if they started through the sh
.
It's reasonable to check in the settings if Android Studio was able to locate the Android SDK.
For example, if you launch the Android Studio as a desktop app, then what is inside the Exec=…
statement of the accosiated .desktop
file?
@igor-ramazanov so the issue appears to be with one of the files in the tadfisher sdk. Would you be able to do me a favour and check in your android-nixpkgs sdk the file [your-sdk-location]/emulator/emulator
. Is this a plain text symlink file, or is it an executable?
When I look at the official sdk downloaded by android studio the emulator/emulator file is an executable. however in android-nixpkgs, this is a text file pointing to .emulator-wrapped
. This single file is causing my avd to crash. the question is, why is it only crashing on my machine and not others?
Contents of emulator/emulator.txt:
#! /nix/store/q8qq40xg2grfh9ry1d9x4g7lq4ra7n81-bash-5.2-p21/bin/bash -e
export QT_QPA_PLATFORM='xcb'
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+':'$LD_LIBRARY_PATH':'}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/':''/nix/store/iidxwcyp8pqhrq3iji17shs4m6gin0kv-systemd-254.6/lib'':'/':'}
LD_LIBRARY_PATH='/nix/store/iidxwcyp8pqhrq3iji17shs4m6gin0kv-systemd-254.6/lib'$LD_LIBRARY_PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH#':'}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH%':'}
export LD_LIBRARY_PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+':'$LD_LIBRARY_PATH':'}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/':''/nix/store/jnlxl2ry9y03vq4skhm26igfd84xwa93-dbus-1.14.10-lib/lib'':'/':'}
LD_LIBRARY_PATH='/nix/store/jnlxl2ry9y03vq4skhm26igfd84xwa93-dbus-1.14.10-lib/lib'$LD_LIBRARY_PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH#':'}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH%':'}
export LD_LIBRARY_PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+':'$LD_LIBRARY_PATH':'}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH/':''/nix/store/53ch4im2ziqjjhr08fphwxkclkqmrqkp-libudev0-shim-1/lib'':'/':'}
LD_LIBRARY_PATH='/nix/store/53ch4im2ziqjjhr08fphwxkclkqmrqkp-libudev0-shim-1/lib'$LD_LIBRARY_PATH
LD_LIBRARY_PATH=${LD_LIBRARY_PATH#':'}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH%':'}
export LD_LIBRARY_PATH
export QT_XKB_CONFIG_ROOT='/nix/store/vrybs7z641yn0qkk4g9h8q5waxa9ljlp-xkeyboard-config-2.40/share/X11/xkb'
export QTCOMPOSE='/nix/store/y8f8j7nb52l30cg8x0clk9k91fpi224v-libX11-1.8.7/share/X11/locale'
exec -a "$0" "/nix/store/vdrgqk9mwqzpg89b5yvkfzf3xy87g05a-emulator-34.2.1/.emulator-wrapped" "$@"