2014-04-20 11:29:10 +02:00
|
|
|
{ stdenv, androidsdk, jdk, ant, androidndk, gnumake, gawk, file, which }:
|
2013-10-15 16:32:16 +02:00
|
|
|
args@{ name, src, platformVersions ? [ "8" ], useGoogleAPIs ? false, antFlags ? ""
|
2012-11-07 21:10:39 +01:00
|
|
|
, release ? false, keyStore ? null, keyAlias ? null, keyStorePassword ? null, keyAliasPassword ? null
|
2014-04-20 11:29:10 +02:00
|
|
|
, useNDK ? false, ...
|
2012-11-07 21:10:39 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert release -> keyStore != null && keyAlias != null && keyStorePassword != null && keyAliasPassword != null;
|
|
|
|
|
|
|
|
let
|
2012-12-28 19:54:15 +01:00
|
|
|
platformName = if stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux" then "linux"
|
2012-11-07 21:10:39 +01:00
|
|
|
else if stdenv.system == "x86_64-darwin" then "macosx"
|
|
|
|
else throw "Platform: ${stdenv.system} is not supported!";
|
|
|
|
|
2013-07-31 18:56:27 +02:00
|
|
|
androidsdkComposition = androidsdk {
|
2013-08-01 11:21:54 +02:00
|
|
|
inherit platformVersions useGoogleAPIs;
|
|
|
|
abiVersions = [];
|
2013-07-31 18:56:27 +02:00
|
|
|
};
|
2012-11-07 21:10:39 +01:00
|
|
|
in
|
2013-10-15 16:32:16 +02:00
|
|
|
stdenv.mkDerivation ({
|
2013-03-21 14:11:58 +01:00
|
|
|
name = stdenv.lib.replaceChars [" "] [""] name;
|
2014-04-20 11:29:10 +02:00
|
|
|
|
2012-11-08 15:01:06 +01:00
|
|
|
ANDROID_HOME = "${androidsdkComposition}/libexec/android-sdk-${platformName}";
|
2012-11-07 21:10:39 +01:00
|
|
|
|
2014-04-20 11:29:10 +02:00
|
|
|
buildInputs = [ jdk ant ] ++
|
|
|
|
stdenv.lib.optional useNDK [ androidndk gnumake gawk file which ];
|
|
|
|
|
2012-11-07 21:10:39 +01: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 11:29:10 +02:00
|
|
|
|
2012-11-07 21:10:39 +01:00
|
|
|
export ANDROID_SDK_HOME=`pwd` # Key files cannot be stored in the user's home directory. This overrides it.
|
2014-04-20 11:29:10 +02:00
|
|
|
${if useNDK then ''
|
|
|
|
export GNUMAKE=${gnumake}/bin/make
|
|
|
|
export NDK_HOST_AWK=${gawk}/bin/gawk
|
|
|
|
${androidndk}/ndk-build
|
|
|
|
'' else ""}
|
2013-08-01 11:21:54 +02:00
|
|
|
ant ${antFlags} ${if release then "release" else "debug"}
|
2012-11-07 21:10:39 +01:00
|
|
|
'';
|
2014-04-20 11:29:10 +02:00
|
|
|
|
2012-11-07 21:10:39 +01:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2013-03-21 14:21:20 +01:00
|
|
|
mv bin/*-${if release then "release" else "debug"}.apk $out
|
2013-03-05 12:29:48 +01:00
|
|
|
|
|
|
|
mkdir -p $out/nix-support
|
2013-03-21 14:11:58 +01:00
|
|
|
echo "file binary-dist \"$(echo $out/*.apk)\"" > $out/nix-support/hydra-build-products
|
2012-11-07 21:10:39 +01:00
|
|
|
'';
|
2013-10-15 16:32:16 +02:00
|
|
|
} //
|
|
|
|
builtins.removeAttrs args ["name"])
|