2014-04-20 09:29:10 +00:00
|
|
|
{ stdenv, androidsdk, jdk, ant, androidndk, gnumake, gawk, file, which }:
|
2013-10-15 14:32:16 +00:00
|
|
|
args@{ name, src, platformVersions ? [ "8" ], useGoogleAPIs ? false, antFlags ? ""
|
2012-11-07 20:10:39 +00:00
|
|
|
, release ? false, keyStore ? null, keyAlias ? null, keyStorePassword ? null, keyAliasPassword ? null
|
2014-04-20 09:29:10 +00:00
|
|
|
, useNDK ? false, ...
|
2012-11-07 20:10:39 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert release -> keyStore != null && keyAlias != null && keyStorePassword != null && keyAliasPassword != null;
|
|
|
|
|
|
|
|
let
|
2013-07-31 16:56:27 +00:00
|
|
|
androidsdkComposition = androidsdk {
|
2013-08-01 09:21:54 +00:00
|
|
|
inherit platformVersions useGoogleAPIs;
|
|
|
|
abiVersions = [];
|
2013-07-31 16:56:27 +00:00
|
|
|
};
|
2012-11-07 20:10:39 +00:00
|
|
|
in
|
2013-10-15 14:32:16 +00:00
|
|
|
stdenv.mkDerivation ({
|
2013-03-21 13:11:58 +00:00
|
|
|
name = stdenv.lib.replaceChars [" "] [""] name;
|
2014-04-20 09:29:10 +00:00
|
|
|
|
2016-09-01 13:56:35 +00:00
|
|
|
ANDROID_HOME = "${androidsdkComposition}/libexec";
|
2012-11-07 20:10:39 +00:00
|
|
|
|
2014-04-20 09:29:10 +00:00
|
|
|
buildInputs = [ jdk ant ] ++
|
|
|
|
stdenv.lib.optional useNDK [ androidndk gnumake gawk file which ];
|
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
buildPhase = ''
|
|
|
|
${stdenv.lib.optionalString release ''
|
|
|
|
|
|
|
|
# Provide key singing attributes
|
|
|
|
( echo "key.store=${keyStore}"
|
|
|
|
echo "key.alias=${keyAlias}"
|
|
|
|
echo "key.store.password=${keyStorePassword}"
|
|
|
|
echo "key.alias.password=${keyAliasPassword}"
|
|
|
|
) >> ant.properties
|
|
|
|
''}
|
2014-04-20 09:29:10 +00:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
export ANDROID_SDK_HOME=`pwd` # Key files cannot be stored in the user's home directory. This overrides it.
|
2014-04-20 09:29:10 +00:00
|
|
|
${if useNDK then ''
|
|
|
|
export GNUMAKE=${gnumake}/bin/make
|
|
|
|
export NDK_HOST_AWK=${gawk}/bin/gawk
|
2014-11-24 08:16:08 +00:00
|
|
|
${androidndk}/bin/ndk-build
|
2014-04-20 09:29:10 +00:00
|
|
|
'' else ""}
|
2013-08-01 09:21:54 +00:00
|
|
|
ant ${antFlags} ${if release then "release" else "debug"}
|
2012-11-07 20:10:39 +00:00
|
|
|
'';
|
2014-04-20 09:29:10 +00:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2013-03-21 13:21:20 +00:00
|
|
|
mv bin/*-${if release then "release" else "debug"}.apk $out
|
2013-03-05 11:29:48 +00:00
|
|
|
|
|
|
|
mkdir -p $out/nix-support
|
2013-03-21 13:11:58 +00:00
|
|
|
echo "file binary-dist \"$(echo $out/*.apk)\"" > $out/nix-support/hydra-build-products
|
2012-11-07 20:10:39 +00:00
|
|
|
'';
|
2013-10-15 14:32:16 +00:00
|
|
|
} //
|
|
|
|
builtins.removeAttrs args ["name"])
|