Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android-studio/android-sdk: cannot install/upgrade Android SDK packages #8650

Closed
bobvanderlinden opened this issue Jul 5, 2015 · 10 comments
Closed

Comments

@bobvanderlinden
Copy link
Member

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 (

idea = recurseIntoAttrs (callPackage ../applications/editors/idea { androidsdk = androidsdk_4_4; });
). 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?

@edwtjo
Copy link
Member

edwtjo commented Jul 5, 2015

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.

@bobvanderlinden
Copy link
Member Author

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?

@geraldus
Copy link

@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?

@jgillich
Copy link
Member

jgillich commented Apr 1, 2016

IMO, this should be reopened as there's still no real solution to the problem.

@bobvanderlinden
Copy link
Member Author

@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?

@Radivarig
Copy link

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.

@bjornfor
Copy link
Contributor

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?

@svanderburg
Copy link
Member

@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)

@bjornfor
Copy link
Contributor

@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?

@svanderburg
Copy link
Member

@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.

phunehehe added a commit to phunehehe/nixpkgs that referenced this issue Aug 10, 2016
This commit fixes 2 main problems:

  - Android Studio comes with its own package manager. The current
    packaging approach doesn't allow such management. As a result the
    package is unusable (see
    NixOS#8650 and
    NixOS#14903). In this version,
    $ANDROID_HOME is _not_ set, allowing Android Studio to deal with the
    Android SDK as it pleases (typically in $HOME/Android/Sdk).

  - Android Studio downloads prebuilt binaries as part of the SDK. These
    tools (e.g. `mksdcard`) have `/lib/ld-linux.so.2` set as the
    interpreter. An FHS environment is used as a work around for that.
@edwtjo edwtjo closed this as completed Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants