1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/pkgs/development/mobile/androidenv/build-gradle-app.nix

109 lines
4.1 KiB
Nix
Raw Normal View History

2018-06-21 17:48:05 +01:00
{ stdenv, androidsdk, jdk, androidndk, gnumake, gawk, file
, which, gradle, fetchurl, buildEnv, runCommand }:
2017-05-16 20:27:27 +01:00
2018-06-21 17:48:05 +01:00
args@{ name, src, platformVersions ? [ "8" ], useGoogleAPIs ? false
, useExtraSupportLibs ? false, useGooglePlayServices ? false
, release ? false, keyStore ? null, keyAlias ? null
, keyStorePassword ? null, keyAliasPassword ? null
, useNDK ? false, buildInputs ? [], mavenDeps, gradleTask
, buildDirectory ? "./.", acceptAndroidSdkLicenses ? false }:
2017-05-16 20:27:27 +01:00
2018-06-21 17:48:05 +01:00
assert release -> keyStore != null;
assert release -> keyAlias != null;
assert release -> keyStorePassword != null;
assert release -> keyAliasPassword != null;
2017-05-16 23:38:23 +01:00
assert acceptAndroidSdkLicenses;
2017-05-16 20:27:27 +01:00
let
2018-06-21 17:48:05 +01:00
inherit (stdenv.lib) optionalString;
m2install = { repo, version, artifactId, groupId
, jarSha256, pomSha256, aarSha256, suffix ? "" }:
2017-05-16 20:27:27 +01:00
let m2Name = "${artifactId}-${version}";
m2Path = "${builtins.replaceStrings ["."] ["/"] groupId}/${artifactId}/${version}";
2018-06-21 17:48:05 +01:00
in runCommand m2Name {} (''
mkdir -p $out/m2/${m2Path}
'' + optionalString (jarSha256 != null) ''
install -D ${fetchurl {
url = "${repo}${m2Path}/${m2Name}${suffix}.jar";
sha256 = jarSha256;
}} $out/m2/${m2Path}/${m2Name}${suffix}.jar
'' + optionalString (pomSha256 != null) ''
install -D ${fetchurl {
url = "${repo}${m2Path}/${m2Name}${suffix}.pom";
sha256 = pomSha256;
}} $out/m2/${m2Path}/${m2Name}${suffix}.pom
'' + optionalString (aarSha256 != null) ''
install -D ${fetchurl {
url = "${repo}${m2Path}/${m2Name}${suffix}.aar";
sha256 = aarSha256;
}} $out/m2/${m2Path}/${m2Name}${suffix}.aar
'');
2017-05-16 20:27:27 +01:00
androidsdkComposition = androidsdk {
2018-06-21 17:48:05 +01:00
inherit platformVersions useGoogleAPIs
useExtraSupportLibs useGooglePlayServices;
2017-05-16 20:27:27 +01:00
abiVersions = [ "armeabi-v7a" ];
};
in
stdenv.mkDerivation ({
name = stdenv.lib.replaceChars [" "] [""] name;
ANDROID_HOME = "${androidsdkComposition}/libexec";
2018-06-21 17:48:05 +01:00
ANDROID_NDK_HOME = "${androidndk}/libexec/${androidndk.name}";
2017-05-16 20:27:27 +01:00
buildInputs = [ jdk gradle ] ++
stdenv.lib.optional useNDK [ androidndk gnumake gawk file which ] ++
buildInputs;
DEPENDENCIES = buildEnv { name = "${name}-maven-deps";
paths = map m2install mavenDeps;
};
buildPhase = ''
2018-06-21 17:48:05 +01:00
${optionalString release ''
2017-05-16 22:22:55 +01:00
# Provide key signing attributes
( echo "RELEASE_STORE_FILE=${keyStore}"
echo "RELEASE_KEY_ALIAS=${keyAlias}"
echo "RELEASE_STORE_PASSWORD=${keyStorePassword}"
echo "RELEASE_KEY_PASSWORD=${keyAliasPassword}"
) >> gradle.properties
2017-05-16 22:22:55 +01:00
''}
2017-05-16 20:27:27 +01:00
buildDir=`pwd`
cp -r $ANDROID_HOME $buildDir/local_sdk
chmod -R 755 local_sdk
export ANDROID_HOME=$buildDir/local_sdk
2018-06-21 17:48:05 +01:00
# Key files cannot be stored in the user's home directory. This
# overrides it.
export ANDROID_SDK_HOME=`pwd`
2017-05-16 20:27:27 +01:00
2018-06-21 17:48:05 +01:00
mkdir -p "$ANDROID_HOME/licenses"
2017-05-16 20:27:27 +01:00
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
export APP_HOME=`pwd`
mkdir -p .m2/repository
2017-06-14 23:01:37 +01:00
if [ -d "$DEPENDENCIES/m2" ] ; then
cp -RL "$DEPENDENCIES"/m2/* .m2/repository/
fi
2017-05-16 20:27:27 +01:00
chmod -R 755 .m2
mkdir -p .m2/repository/com/android/support
cp -RL local_sdk/extras/android/m2repository/com/android/support/* .m2/repository/com/android/support/
cp -RL local_sdk/extras/google/m2repository/* .m2/repository/
gradle ${gradleTask} --offline --no-daemon -g ./tmp -Dmaven.repo.local=`pwd`/.m2/repository
'';
installPhase = ''
mkdir -p $out
mv ${buildDirectory}/build/outputs/apk/*.apk $out
2018-06-21 17:48:05 +01:00
2017-05-16 20:27:27 +01:00
mkdir -p $out/nix-support
echo "file binary-dist \"$(echo $out/*.apk)\"" > $out/nix-support/hydra-build-products
'';
meta = {
license = stdenv.lib.licenses.unfree;
};
2018-06-21 17:48:05 +01:00
} // builtins.removeAttrs args ["name" "mavenDeps"])