Hello everybody.
Has anybody managed to launch emulators for Android app development without Android Studio? Android Studio is quite heavy to run, and I mostly need just emulator to test some things - but doing it on NixOS turned out to be extra painful.
So far I have found this topic - in which the OP didn’t find a solution.
I followed his link -Nixpkgs Reference Manual - and did everything by the book, but I get an error sayin that “androidenv” is undefined.
Android Studio itself runs fine, and emulator inside of it too - but its super laggy to run it on my laptop.
Can somebody share their setup or steps, so that Ideally I would be able to only launch emulators via CLI without Android Studio?
2 Likes
from the nixpkgs reference manual link above
{
pkgs ? import <nixpkgs> {
config = {
android_sdk.accept_license = true;
allowUnfree = true;
};
},
}:
pkgs.androidenv.emulateApp {
name = "emulate-MyAndroidApp";
platformVersion = "33";
abiVersion = "x86_64"; # armeabi-v7a, mips, x86_64
systemImageType = "google_apis_playstore";
}
I’ve tried this, and an emulator does come up with nix-build && ./result/bin/run-test-emulator
can you check if it doesn’t work for you?
if <nixpkgs>
is not working you can try one of the methods mentioned here and use the nixos-unstable branch.
And if you post under Help category on discourse, you can mark a comment as a solution (if it ever gets solved)
1 Like
Thank you for replying!
I am sorry - I am not a big NixOS wizzard - having hard time with the config…
But I did what you said and at least, it rebuilt without any errors.
I did this:
# Accepting licenses and allowing unfree packages
nixpkgs.config = {
android_sdk.accept_license = true;
allowUnfree = true;
};
# Adding androidenv setup to system packages
environment.systemPackages = with pkgs; [
# Other packages...
(pkgs.androidenv.emulateApp {
name = "emulate-MyAndroidApp";
platformVersion = "33";
abiVersion = "x86_64"; # armeabi-v7a, mips, x86_64
systemImageType = "google_apis_playstore";
})
];
But how do I run it? Does it also install “sdkmanager”, “avdmanager” - which, as I understood, are required to launch an emulator?
I built it successfully with your code, but how to launch this emulator?
As you added it to environment.systemPackages
it will be in your environment as run-test-emulator
. you can open a new terminal and try running run-test-emulator
.
But I think project level shell.nix (or if you are familiar with flakes, a flake.nix) might be a better option.
1 Like
we can chat on matrix, @phanirithvij.matrix.org
search for phanirithvij
on element if the link isn’t working
1 Like
Yes, now something is happening but I get this error:
[nikita@nixos:~]$ run-test-emulator
Looking for a free TCP port in range 5554-5584
* daemon not running; starting now at tcp:5037
* daemon started successfully
We have a free TCP port: 5554
[=======================================] 100% Fetch remote repository...
Auto-selecting single ABI x86_64
Do you wish to create a custom hardware profile? [no] \nLaunch the emulator
Waiting until the emulator has booted the device and the package manager is ready...
INFO | Storing crashdata in: /tmp/android-nikita/emu-crash-35.1.4.db, detection is enabled for process: 29520
INFO | Android emulator version 35.1.4.0 (build_id 11672324) (CL:N/A)
INFO | AVD device has path /tmp/nix-android-user-home-NLFY/avd/../avd/device.avd
INFO | trying to check whether /home/nikita/Android/Sdk is a valid sdk root
WARNING | /home/nikita/Android/Sdk/system-images/android-33/google_apis_playstore/x86_64/ is not a valid directory.
WARNING | emulator has searched the above paths but found no valid sdk root directory.
PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value [/nix/store/xvgh2brfbcjjziz516xpdfl8b0063xyk-androidsdk/libexec/android-sdk]!
Can you please add me on matrix chat? I am unable to add it, sorry again
@nikita0x:matrix.org
In the end, @phanirithvij answer was the solution.
But not only that - that godlike person spoon fed me NixOS information and patiently explained all my gaps and about nix, packages, system - everything for 4.30 hours!!!
I mean, not only he was patient and helpful but also super knowledgeable about NixOS.
If anybody need an expert - please contact and/or hire him!
1 Like