lol
1{ composeAndroidPackages, stdenv, lib, ant, jdk, gnumake, gawk }:
2
3{ name
4, release ? false, keyStore ? null, keyAlias ? null, keyStorePassword ? null, keyAliasPassword ? null
5, antFlags ? ""
6, ...
7}@args:
8
9assert release -> keyStore != null && keyAlias != null && keyStorePassword != null && keyAliasPassword != null;
10
11let
12 androidSdkFormalArgs = lib.functionArgs composeAndroidPackages;
13 androidArgs = builtins.intersectAttrs androidSdkFormalArgs args;
14 androidsdk = (composeAndroidPackages androidArgs).androidsdk;
15
16 extraArgs = removeAttrs args ([ "name" ] ++ builtins.attrNames androidSdkFormalArgs);
17in
18stdenv.mkDerivation ({
19 name = lib.replaceStrings [" "] [""] name; # Android APKs may contain white spaces in their names, but Nix store paths cannot
20 ANDROID_HOME = "${androidsdk}/libexec/android-sdk";
21 buildInputs = [ jdk ant ];
22 buildPhase = ''
23 ${lib.optionalString release ''
24 # Provide key singing attributes
25 ( echo "key.store=${keyStore}"
26 echo "key.alias=${keyAlias}"
27 echo "key.store.password=${keyStorePassword}"
28 echo "key.alias.password=${keyAliasPassword}"
29 ) >> ant.properties
30 ''}
31
32 export ANDROID_SDK_HOME=`pwd` # Key files cannot be stored in the user's home directory. This overrides it.
33
34 ${lib.optionalString (args ? includeNDK && args.includeNDK) ''
35 export GNUMAKE=${gnumake}/bin/make
36 export NDK_HOST_AWK=${gawk}/bin/gawk
37 ${androidsdk}/libexec/android-sdk/ndk-bundle/ndk-build
38 ''}
39 ant ${antFlags} ${if release then "release" else "debug"}
40 '';
41 installPhase = ''
42 mkdir -p $out
43 mv bin/*-${if release then "release" else "debug"}.apk $out
44
45 mkdir -p $out/nix-support
46 echo "file binary-dist \"$(echo $out/*.apk)\"" > $out/nix-support/hydra-build-products
47 '';
48} // extraArgs)