At the moment the different Android SDKs are packaged in NixOS. However, Google made its own package manager for these packages: Android SDK Manager. The Android SDK Manager cannot install or upgrade packages, because ANDROID_HOME is set to a /nix/store path, which is read-only.
In addition, Android Studio has a dependency on one Android SDK. At the moment it is androidsdk_4_4
(https://github.com/NixOS/nixpkgs/blob/af3d395cfe4666973e4cf4105a1b05b509ff1bab/pkgs/top-level/all-packages.nix#L11456). If one wants to develop (using Android Studio) for a different SDK, then you'd need to alter nixpkgs or nixpkgs/config.nix to do so.
I don't know whether I'm missing something, but for actual day-to-day usage it is probably more practical to let Androids SDK Manager do its thing in a home directory and not set ANDROID_HOME
to a /nix/store
path.
What is the best way to solve this problem? Those who use Android Studio on NixOS, how do you make this practical?
As a non user of android-studio/sdk; If you are an android developer please consider adding yourself to the android-studio maintainers and submitting the appropriate changes to whatever you feel is more reasonable. Right now you need to use overrides. I think above makes a good case for removing ANDROID_HOME from the wrapper.
Thanks for the reply. Too bad there aren't many android devs using nix.
I have tried removing ANDROID_HOME from the wrapper. It seems many of the tools in Android SDK will not work on NixOS out of the box. mksdcard
is a static binary that fails to run. It is already patched in nixpkgs. android
(the SDK Manager) doesn't run because it needs additional libraries it cannot find.
I've checked whether it would be possible to let Android SDK Manager from nixpkgs download SDKs to a different directory (HOME/something) instead of deriving the location from its executable. I haven't found a way to do this.
Next best thing is to use nixpkgs/config.nix to make SDKs available to the development environment. Not very practical, but with the current situation of Androids tools there doesn't seem to be another way.
I'll close this for now. If there pops up some option to still be able to do this I'll reopen it again.
Also, I don't mind being a maintainer for android-studio. Should I open a PR?
@bobvanderlinden sorry for noise, so I want to stick with NixOS is there some way to develop Android apps (e.g. virtual box, running Studio GUI from docker container, or something else)? Can you suggest something?
IMO, this should be reopened as there's still no real solution to the problem.
@jgillich Agreed.
@geraldus I'm sad to say that I don't use Nix for Android development at the moment :( It wasn't really practical.
I recently became aware of buildFHSChrootEnv
. Maybe it is a good idea to have Android Studio running inside of a 'normal' FHS chroot where tools like android
and mksdcard
and binaries that will reside in your home dir can operate properly. It isn't the ideal solution, but it might be a practical one?
Yep, when I run android
from androidsdk
package, I can't install or update. It shows error: Failed to create directory /nix/store/...-android-sdk-24.4/libexec/android-sdk-linux/temp
by trying to make directory temp
.
Did anyone try a LD_PRELOAD library that redirects the SDK directory? Or by some other means redirect accesse from that nix store path to $HOME?
@Radivarig You can't use the 'android' tool from androidenv.androidsdk
to install any plugins, as packages deployed by the Nix package manager are stored in a read-only Nix store. Instead, you should deploy the plugins with the Nix package manager as well.
The androidenv
attribute set contains a number of predefined compositions. For example, the following would deploy everything you would typically need for development for Android 6.0:
$ nix-env -f '<nixpkgs>' -iA androidenv.androidsdk_6_0
You can also configure the plugins yourself:
with import <nixpkgs> {};
androidenv.androidsdk {
platformVersions = [ "23" ]; # Anything between 2 - 23
abiVersions = [ "armeabi-v7a" ]; # Also possible: x86, mips, x86_64
useGoogleAPIs = true;
useExtraSupportLibs = true;
useGooglePlayServices = true;
}
and install the above SDK composition, by running:
$ nix-env -i $(nix-build myandroidsdk.nix)
@svanderburg: So these open issues we have about android-studio being unuseable on Nix(OS) is basically a due misunderstandings (and possibly lack of documentation...)? Android development is OK with Nix?
@bjornfor If Android development is OK with Nix? There are always things that can be improved and it depends on what kinds of applications you want to develop. For example, not all the plugins that the Android SDK provides have been packaged. The Nixpkgs documentation can be improved as well, but I think this also applies to other areas of Nixpkgs.
I don't want to claim that these android-studio issues are caused by a lack of understanding. There are many reasons for it. There may be some functionality missing, and there is no (convenient) integration pattern allowing one to use a Nix-deployed Android SDK in android-studio. I think the latter is the biggest issue in getting android studio to work.
The primary reason for me developing the androidenv package is to automate Android builds on Hydra. For me, it covers all my use cases in the development projects that I'm involved with. For example, last year I have built +/- 100 different kinds of apps with it.
Most helpful comment
@bjornfor If Android development is OK with Nix? There are always things that can be improved and it depends on what kinds of applications you want to develop. For example, not all the plugins that the Android SDK provides have been packaged. The Nixpkgs documentation can be improved as well, but I think this also applies to other areas of Nixpkgs.
I don't want to claim that these android-studio issues are caused by a lack of understanding. There are many reasons for it. There may be some functionality missing, and there is no (convenient) integration pattern allowing one to use a Nix-deployed Android SDK in android-studio. I think the latter is the biggest issue in getting android studio to work.
The primary reason for me developing the androidenv package is to automate Android builds on Hydra. For me, it covers all my use cases in the development projects that I'm involved with. For example, last year I have built +/- 100 different kinds of apps with it.