0

I have existing Android apps, that I would like to continue building after I switched to NixOS.

I followed several instructions that are basically allways based on what is described in the Nixpkgs manual: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/android.section.md

The problem I have is: when I build my own environment with something like this:

with import <nixpkgs> {};

let
  androidComposition = androidenv.composeAndroidPackages {
    toolsVersion = "25.2.5";
    platformToolsVersion = "27.0.1";
    buildToolsVersions = [ "27.0.3" ];
    includeEmulator = false;
    emulatorVersion = "27.2.0";
    platformVersions = [ "24" ];
    includeSources = false;
    includeDocs = false;
    includeSystemImages = false;
    systemImageTypes = [ "default" ];
    abiVersions = [ "armeabi-v7a" ];
    lldbVersions = [ "2.0.2558144" ];
    cmakeVersions = [ "3.6.4111459" ];
    includeNDK = false;
    ndkVersion = "16.1.4479499";
    useGoogleAPIs = false;
    useGoogleTVAddOns = false;
    includeExtras = [
      "extras;google;gcm"
    ];
  };
in
androidComposition.androidsdk

Then there is no environment variable ANDROID_HOME defined and calling gradlew of my project will fail complaining that. If I try to find some place where I could manually direct ANDROID_HOME to, then I fail because the gradle build will complain I didn't accept the license agreement of the SDK. (And I also cannot accept the license because I would have to do this in the read-only nix store.)

I also tried to build the complete app using Nix with something like this:

with import <nixpkgs> {};

androidenv.buildApp {
  name = "Tove";
  src = ./tove;
  release = true;

  keyStore = ./tove/release.keystore;
  keyAlias = "ReleaseKey";
  keyStorePassword = "XXXXXXXX";
  keyAliasPassword = "XXXXXXXX";

  platformVersions = [ "28" ];

  includeNDK = false;
}

But it seems to me, that this only supports Ant based builds. But I cannot change the complete build environment to Ant, because my colleagues would complain then. The error I get in that case is:

these derivations will be built:
  /nix/store/1pnd3zra0p6q2w4nij8mp49b1jr6g0p2-Tove.drv
building '/nix/store/1pnd3zra0p6q2w4nij8mp49b1jr6g0p2-Tove.drv'...
unpacking sources
unpacking source archive /nix/store/l1lphdp98cxfhq5dahr63ipjrz9qbn6l-tove
source root is tove
patching sources
configuring
no configure script, doing nothing
building
Buildfile: build.xml does not exist!
Build failed
builder for '/nix/store/1pnd3zra0p6q2w4nij8mp49b1jr6g0p2-Tove.drv' failed with exit code 1
error: build of '/nix/store/1pnd3zra0p6q2w4nij8mp49b1jr6g0p2-Tove.drv' failed

How do I get an environment where I can build Android Apps using gradle from within NixOS? Is there any help or tutorials available?

Matthias Wimmer
  • 3,789
  • 2
  • 22
  • 41
  • You mentioned about licenses. Was is related to emulators? Maybe this will help You some - https://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences – deadfish Jun 05 '19 at 13:35
  • @deadfish thanks for the link, but unfortunately it doesn't work (or I'm doing it wrong). It would try to accept the license by writing a file to a read only location in the file system (the nix store). – Matthias Wimmer Jun 05 '19 at 13:38

0 Answers0