Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkgs/development/mobile/androidenv/androidsdk.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, stdenv_32bit, fetchurl, unzip, makeWrapper
{ stdenv, stdenv_32bit, fetchurl, fetchzip, unzip, makeWrapper
, platformTools, buildTools, support, supportRepository, platforms, sysimages, addons, sources
, libX11, libXext, libXrender, libxcb, libXau, libXdmcp, libXtst, libGLU_combined, alsaLib
, freetype, fontconfig, glib, gtk2, atk, file, jdk, coreutils, libpulseaudio, dbus
Expand All @@ -8,7 +8,15 @@
{ platformVersions, abiVersions, useGoogleAPIs, useExtraSupportLibs ? false
, useGooglePlayServices ? false, useInstantApps ? false }:

let inherit (stdenv.lib) makeLibraryPath; in
let inherit (stdenv.lib) makeLibraryPath;

googleRepository = let version = "gms_v9_rc41_wear_2_0_rc6";
in fetchzip rec {
url = "https://dl-ssl.google.com/android/repository/google_m2repository_${version}.zip";
sha256 = "0k99xmynv0k62d301zx5jnjkddflr51i5lb02l9incg7m5cn8kzx";
};

in

stdenv.mkDerivation rec {
name = "android-sdk-${version}";
Expand Down Expand Up @@ -168,6 +176,8 @@ stdenv.mkDerivation rec {
${stdenv.lib.optionalString useInstantApps
"ln -s ${addons.instant_apps}/whsdk instantapps"}

ln -s ${googleRepository} m2repository

cd ../..

# Symlink required sources
Expand Down
104 changes: 104 additions & 0 deletions pkgs/development/mobile/androidenv/build-gradle-app.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{ stdenv, androidsdk, jdk, androidndk, gnumake, gawk, file
, which, gradle, fetchurl, buildEnv, runCommand }:

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 }:

assert release -> keyStore != null;
assert release -> keyAlias != null;
assert release -> keyStorePassword != null;
assert release -> keyAliasPassword != null;
assert acceptAndroidSdkLicenses;

let
inherit (stdenv.lib) optionalString;

m2install = { repo, version, artifactId, groupId
, jarSha256, pomSha256, aarSha256, suffix ? "" }:
let m2Name = "${artifactId}-${version}";
m2Path = "${builtins.replaceStrings ["."] ["/"] groupId}/${artifactId}/${version}";
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
'');

androidsdkComposition = androidsdk {
inherit platformVersions useGoogleAPIs
useExtraSupportLibs useGooglePlayServices;
abiVersions = [ "armeabi-v7a" ];
};
in
stdenv.mkDerivation ({
name = stdenv.lib.replaceChars [" "] [""] name;

ANDROID_HOME = "${androidsdkComposition}/libexec";
ANDROID_NDK_HOME = "${androidndk}/libexec/${androidndk.name}";

buildInputs = [ jdk gradle ] ++
stdenv.lib.optional useNDK [ androidndk gnumake gawk file which ] ++
buildInputs;

DEPENDENCIES = buildEnv { name = "${name}-maven-deps";
paths = map m2install mavenDeps;
};

buildPhase = ''
${optionalString release ''
# 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
''}
buildDir=`pwd`
cp -r $ANDROID_HOME $buildDir/local_sdk
chmod -R 755 local_sdk
export ANDROID_HOME=$buildDir/local_sdk
# Key files cannot be stored in the user's home directory. This
# overrides it.
export ANDROID_SDK_HOME=`pwd`

mkdir -p "$ANDROID_HOME/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ericson2314 Do you think this is okay to do? I guess the "assert acceptAndroidSdkLicenses" is basically covering this acceptance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I...suppose so!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this hash?

echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"

export APP_HOME=`pwd`

mkdir -p .m2/repository
if [ -d "$DEPENDENCIES/m2" ] ; then
cp -RL "$DEPENDENCIES"/m2/* .m2/repository/
fi
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

mkdir -p $out/nix-support
echo "file binary-dist \"$(echo $out/*.apk)\"" > $out/nix-support/hydra-build-products
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am actually unsure what this is doing? @Ericson2314

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know either. @ElvishJerricco might.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea what this does

'';
} // builtins.removeAttrs args ["name" "mavenDeps"])
23 changes: 19 additions & 4 deletions pkgs/development/mobile/androidenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
, includeSources ? true
}:

# TODO: use callPackage instead of import to avoid so many inherits

rec {
platformTools = import ./platform-tools.nix {
inherit buildPackages pkgs;
Expand Down Expand Up @@ -46,11 +48,16 @@ rec {
};

androidsdk = import ./androidsdk.nix {
inherit (pkgs) stdenv fetchurl unzip makeWrapper;
inherit (pkgs) zlib glxinfo freetype fontconfig glib gtk2 atk libGLU_combined file alsaLib jdk coreutils libpulseaudio dbus;
inherit (pkgs.xorg) libX11 libXext libXrender libxcb libXau libXdmcp libXtst xkeyboardconfig;
inherit (pkgs) stdenv fetchurl unzip makeWrapper zlib
glxinfo freetype fontconfig glib gtk2 atk
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;
};
Expand Down Expand Up @@ -215,6 +222,8 @@ rec {
useInstantApps = true;
};

androidsdk_latest = androidsdk_8_0;

androidndk_10e = import ./androidndk.nix {
inherit (buildPackages)
p7zip makeWrapper;
Expand Down Expand Up @@ -296,4 +305,10 @@ rec {
androidndk = androidndk_10e;
targetAndroidndkPkgs = targetPackages.androidenv.androidndkPkgs_10e;
};

buildGradleApp = import ./build-gradle-app.nix {
inherit (pkgs) stdenv jdk gnumake gawk file runCommand
which gradle fetchurl buildEnv;
inherit androidsdk androidndk;
};
}