androidenv.buildGradleApp: refactor
This commit is contained in:
parent
2e8feba171
commit
b72da4bee8
@ -176,7 +176,7 @@ stdenv.mkDerivation rec {
|
|||||||
${stdenv.lib.optionalString useInstantApps
|
${stdenv.lib.optionalString useInstantApps
|
||||||
"ln -s ${addons.instant_apps}/whsdk instantapps"}
|
"ln -s ${addons.instant_apps}/whsdk instantapps"}
|
||||||
|
|
||||||
ln -s ${googleRepository}/m2repository
|
ln -s ${googleRepository} m2repository
|
||||||
|
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
|
@ -1,66 +1,48 @@
|
|||||||
{ stdenv, androidsdk, jdk, androidndk, gnumake, gawk, file, which, gradle, fetchurl, buildEnv }:
|
{ stdenv, androidsdk, jdk, androidndk, gnumake, gawk, file
|
||||||
|
, which, gradle, fetchurl, buildEnv, runCommand }:
|
||||||
|
|
||||||
args@{ name, src, platformVersions ? [ "8" ], useGoogleAPIs ? false, useExtraSupportLibs ? false, useGooglePlayServices ? false
|
args@{ name, src, platformVersions ? [ "8" ], useGoogleAPIs ? false
|
||||||
, release ? false, keyStore ? null, keyAlias ? null, keyStorePassword ? null, keyAliasPassword ? null
|
, useExtraSupportLibs ? false, useGooglePlayServices ? false
|
||||||
, useNDK ? false, buildInputs ? [], mavenDeps, gradleTask, buildDirectory ? "./.", acceptAndroidSdkLicenses ? false
|
, release ? false, keyStore ? null, keyAlias ? null
|
||||||
}:
|
, keyStorePassword ? null, keyAliasPassword ? null
|
||||||
|
, useNDK ? false, buildInputs ? [], mavenDeps, gradleTask
|
||||||
|
, buildDirectory ? "./.", acceptAndroidSdkLicenses ? false }:
|
||||||
|
|
||||||
assert release -> keyStore != null && keyAlias != null && keyStorePassword != null && keyAliasPassword != null;
|
assert release -> keyStore != null;
|
||||||
|
assert release -> keyAlias != null;
|
||||||
|
assert release -> keyStorePassword != null;
|
||||||
|
assert release -> keyAliasPassword != null;
|
||||||
assert acceptAndroidSdkLicenses;
|
assert acceptAndroidSdkLicenses;
|
||||||
|
|
||||||
let
|
let
|
||||||
m2install = { repo, version, artifactId, groupId, jarSha256, pomSha256, aarSha256, suffix ? "" }:
|
inherit (stdenv.lib) optionalString;
|
||||||
|
|
||||||
|
m2install = { repo, version, artifactId, groupId
|
||||||
|
, jarSha256, pomSha256, aarSha256, suffix ? "" }:
|
||||||
let m2Name = "${artifactId}-${version}";
|
let m2Name = "${artifactId}-${version}";
|
||||||
m2Path = "${builtins.replaceStrings ["."] ["/"] groupId}/${artifactId}/${version}";
|
m2Path = "${builtins.replaceStrings ["."] ["/"] groupId}/${artifactId}/${version}";
|
||||||
m2PomFilename = "${m2Name}${suffix}.pom";
|
in runCommand m2Name {} (''
|
||||||
m2JarFilename = "${m2Name}${suffix}.jar";
|
mkdir -p $out/m2/${m2Path}
|
||||||
m2AarFilename = "${m2Name}${suffix}.aar";
|
'' + optionalString (jarSha256 != null) ''
|
||||||
m2Jar =
|
install -D ${fetchurl {
|
||||||
if jarSha256 == null
|
url = "${repo}${m2Path}/${m2Name}${suffix}.jar";
|
||||||
then null
|
sha256 = jarSha256;
|
||||||
else fetchurl {
|
}} $out/m2/${m2Path}/${m2Name}${suffix}.jar
|
||||||
sha256 = jarSha256;
|
'' + optionalString (pomSha256 != null) ''
|
||||||
url = "${repo}${m2Path}/${m2JarFilename}";
|
install -D ${fetchurl {
|
||||||
};
|
url = "${repo}${m2Path}/${m2Name}${suffix}.pom";
|
||||||
m2Pom =
|
sha256 = pomSha256;
|
||||||
if pomSha256 == null
|
}} $out/m2/${m2Path}/${m2Name}${suffix}.pom
|
||||||
then null
|
'' + optionalString (aarSha256 != null) ''
|
||||||
else fetchurl {
|
install -D ${fetchurl {
|
||||||
sha256 = pomSha256;
|
url = "${repo}${m2Path}/${m2Name}${suffix}.aar";
|
||||||
url = "${repo}${m2Path}/${m2PomFilename}";
|
sha256 = aarSha256;
|
||||||
};
|
}} $out/m2/${m2Path}/${m2Name}${suffix}.aar
|
||||||
m2Aar =
|
'');
|
||||||
if aarSha256 == null
|
|
||||||
then null
|
|
||||||
else fetchurl {
|
|
||||||
sha256 = aarSha256;
|
|
||||||
url = "${repo}${m2Path}/${m2AarFilename}";
|
|
||||||
};
|
|
||||||
in stdenv.mkDerivation rec {
|
|
||||||
name = m2Name;
|
|
||||||
inherit m2Name m2Path m2Pom m2Jar m2Aar m2JarFilename m2PomFilename m2AarFilename;
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out/m2/$m2Path
|
|
||||||
${if m2Jar != null
|
|
||||||
then "cp $m2Jar $out/m2/$m2Path/$m2JarFilename"
|
|
||||||
else ""}
|
|
||||||
${if m2Pom != null
|
|
||||||
then "cp $m2Pom $out/m2/$m2Path/$m2PomFilename"
|
|
||||||
else ""}
|
|
||||||
${if m2Aar != null
|
|
||||||
then "cp $m2Aar $out/m2/$m2Path/$m2AarFilename"
|
|
||||||
else ""}
|
|
||||||
'';
|
|
||||||
|
|
||||||
phases = "installPhase";
|
|
||||||
};
|
|
||||||
platformName = if stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux" then "linux"
|
|
||||||
else if stdenv.system == "x86_64-darwin" then "macosx"
|
|
||||||
else throw "Platform: ${stdenv.system} is not supported!";
|
|
||||||
|
|
||||||
androidsdkComposition = androidsdk {
|
androidsdkComposition = androidsdk {
|
||||||
inherit platformVersions useGoogleAPIs useExtraSupportLibs useGooglePlayServices;
|
inherit platformVersions useGoogleAPIs
|
||||||
|
useExtraSupportLibs useGooglePlayServices;
|
||||||
abiVersions = [ "armeabi-v7a" ];
|
abiVersions = [ "armeabi-v7a" ];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
@ -68,7 +50,7 @@ stdenv.mkDerivation ({
|
|||||||
name = stdenv.lib.replaceChars [" "] [""] name;
|
name = stdenv.lib.replaceChars [" "] [""] name;
|
||||||
|
|
||||||
ANDROID_HOME = "${androidsdkComposition}/libexec";
|
ANDROID_HOME = "${androidsdkComposition}/libexec";
|
||||||
ANDROID_NDK_HOME = "${androidndk}/libexec/android-ndk-r10e";
|
ANDROID_NDK_HOME = "${androidndk}/libexec/${androidndk.name}";
|
||||||
|
|
||||||
buildInputs = [ jdk gradle ] ++
|
buildInputs = [ jdk gradle ] ++
|
||||||
stdenv.lib.optional useNDK [ androidndk gnumake gawk file which ] ++
|
stdenv.lib.optional useNDK [ androidndk gnumake gawk file which ] ++
|
||||||
@ -79,7 +61,7 @@ stdenv.mkDerivation ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
${stdenv.lib.optionalString release ''
|
${optionalString release ''
|
||||||
# Provide key signing attributes
|
# Provide key signing attributes
|
||||||
( echo "RELEASE_STORE_FILE=${keyStore}"
|
( echo "RELEASE_STORE_FILE=${keyStore}"
|
||||||
echo "RELEASE_KEY_ALIAS=${keyAlias}"
|
echo "RELEASE_KEY_ALIAS=${keyAlias}"
|
||||||
@ -91,9 +73,11 @@ stdenv.mkDerivation ({
|
|||||||
cp -r $ANDROID_HOME $buildDir/local_sdk
|
cp -r $ANDROID_HOME $buildDir/local_sdk
|
||||||
chmod -R 755 local_sdk
|
chmod -R 755 local_sdk
|
||||||
export ANDROID_HOME=$buildDir/local_sdk
|
export ANDROID_HOME=$buildDir/local_sdk
|
||||||
export ANDROID_SDK_HOME=`pwd` # Key files cannot be stored in the user's home directory. This overrides it.
|
# Key files cannot be stored in the user's home directory. This
|
||||||
|
# overrides it.
|
||||||
|
export ANDROID_SDK_HOME=`pwd`
|
||||||
|
|
||||||
mkdir "$ANDROID_HOME/licenses" || true
|
mkdir -p "$ANDROID_HOME/licenses"
|
||||||
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
|
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
|
||||||
|
|
||||||
@ -113,9 +97,8 @@ stdenv.mkDerivation ({
|
|||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
mv ${buildDirectory}/build/outputs/apk/*.apk $out
|
mv ${buildDirectory}/build/outputs/apk/*.apk $out
|
||||||
|
|
||||||
mkdir -p $out/nix-support
|
mkdir -p $out/nix-support
|
||||||
echo "file binary-dist \"$(echo $out/*.apk)\"" > $out/nix-support/hydra-build-products
|
echo "file binary-dist \"$(echo $out/*.apk)\"" > $out/nix-support/hydra-build-products
|
||||||
'';
|
'';
|
||||||
} //
|
} // builtins.removeAttrs args ["name" "mavenDeps"])
|
||||||
builtins.removeAttrs args ["name" "mavenDeps"])
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
, includeSources ? true
|
, includeSources ? true
|
||||||
}:
|
}:
|
||||||
|
|
||||||
|
# TODO: use callPackage instead of import to avoid so many inherits
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
platformTools = import ./platform-tools.nix {
|
platformTools = import ./platform-tools.nix {
|
||||||
inherit buildPackages pkgs;
|
inherit buildPackages pkgs;
|
||||||
@ -46,11 +48,16 @@ rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
androidsdk = import ./androidsdk.nix {
|
androidsdk = import ./androidsdk.nix {
|
||||||
inherit (pkgs) stdenv fetchurl unzip makeWrapper;
|
inherit (pkgs) stdenv fetchurl unzip makeWrapper zlib
|
||||||
inherit (pkgs) zlib glxinfo freetype fontconfig glib gtk2 atk libGLU_combined file alsaLib jdk coreutils libpulseaudio dbus;
|
glxinfo freetype fontconfig glib gtk2 atk
|
||||||
inherit (pkgs.xorg) libX11 libXext libXrender libxcb libXau libXdmcp libXtst xkeyboardconfig;
|
libGLU_combined file alsaLib jdk coreutils
|
||||||
|
libpulseaudio dbus fetchzip;
|
||||||
|
inherit (pkgs.xorg) libX11 libXext libXrender
|
||||||
|
libxcb libXau libXdmcp libXtst xkeyboardconfig;
|
||||||
|
|
||||||
inherit platformTools buildTools support supportRepository platforms sysimages addons sources includeSources;
|
inherit platformTools buildTools support
|
||||||
|
supportRepository platforms sysimages
|
||||||
|
addons sources includeSources;
|
||||||
|
|
||||||
stdenv_32bit = pkgs_i686.stdenv;
|
stdenv_32bit = pkgs_i686.stdenv;
|
||||||
};
|
};
|
||||||
@ -298,7 +305,8 @@ rec {
|
|||||||
};
|
};
|
||||||
|
|
||||||
buildGradleApp = import ./build-gradle-app.nix {
|
buildGradleApp = import ./build-gradle-app.nix {
|
||||||
inherit (pkgs) stdenv jdk gnumake gawk file which gradle fetchurl buildEnv;
|
inherit (pkgs) stdenv jdk gnumake gawk file runCommand
|
||||||
|
which gradle fetchurl buildEnv;
|
||||||
inherit androidsdk androidndk;
|
inherit androidsdk androidndk;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user