Add Android NDK Nix expression

This commit is contained in:
Pedro Pombeiro 2019-03-03 01:34:06 +01:00
parent 2ac5ee019e
commit 87a7aacd68
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
6 changed files with 71 additions and 35 deletions

View File

@ -10,6 +10,7 @@ in with pkgs;
let
_stdenv = stdenvNoCC; # TODO: Try to use stdenv for Darwin
statusDesktop = callPackage ./scripts/lib/setup/nix/desktop { stdenv = _stdenv; };
statusMobile = callPackage ./scripts/lib/setup/nix/mobile { stdenv = _stdenv; };
nodeInputs = import ./scripts/lib/setup/nix/global-node-packages/output {
# The remaining dependencies come from Nixpkgs
inherit pkgs;
@ -33,8 +34,8 @@ in with pkgs;
maven
ncurses
ps # used in scripts/start-react-native.sh
openjdk
statusDesktop.buildInputs
statusMobile.buildInputs
watchman
unzip
wget
@ -43,17 +44,8 @@ in with pkgs;
++ lib.optional isLinux gcc7;
shellHook = ''
${statusDesktop.shellHook}
${statusMobile.shellHook}
local toolversion="$(git rev-parse --show-toplevel)/scripts/toolversion"
export JAVA_HOME="${openjdk}"
export ANDROID_HOME=~/.status/Android/Sdk
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_NDK_ROOT="$ANDROID_SDK_ROOT/android-ndk-$($toolversion android-ndk)"
export ANDROID_NDK_HOME="$ANDROID_NDK_ROOT"
export ANDROID_NDK="$ANDROID_NDK_ROOT"
export PATH="$ANDROID_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$PATH"
[ -d "$ANDROID_NDK_ROOT" ] || ./scripts/setup # we assume that if the Android NDK dir does not exist, make setup needs to be run
[ -d "$ANDROID_SDK_ROOT" ] || ./scripts/setup # we assume that if the Android SDK dir does not exist, make setup needs to be run
'';
}
}

View File

@ -91,23 +91,3 @@ function use_android_sdk() {
scripts/generate-keystore.sh
}
function install_android_ndk() {
if [ -d "$ANDROID_NDK_ROOT" ]; then
cecho "@green[[Android NDK already installed.]]"
else
local ANDROID_NDK_VERSION=$(toolversion android-ndk)
local _ndkParentDir=$(dirname $ANDROID_NDK_ROOT)
mkdir -p $_ndkParentDir
cecho "@cyan[[Downloading Android NDK.]]"
local PLATFORM=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
download_url . android-ndk.zip https://dl.google.com/android/repository/android-ndk-$ANDROID_NDK_VERSION-$PLATFORM-x86_64.zip && \
cecho "@cyan[[Extracting Android NDK to $_ndkParentDir.]]" && \
unzip -q -o ./android-ndk.zip -d "$_ndkParentDir" && \
rm -f ./android-ndk.zip && \
_ndkTargetDir="$_ndkParentDir/$(ls $_ndkParentDir | grep ndk)" && \
cecho "@blue[[Android NDK installation completed in $_ndkTargetDir.]]"
fi
}

View File

@ -0,0 +1,40 @@
###
### TODO: This Nix expression is a poor-man's package that just wraps the Android NDK download
### Since the executables' dependencies don't point to /nix/store, it isn't a pure package
### so it won't work e.g. on NixOS
###
{ stdenv, fetchzip }:
let
ndk-version = "r10e";
archives = {
macosx = fetchzip {
url = "https://dl.google.com/android/repository/android-ndk-${ndk-version}-darwin-x86_64.zip";
sha256 = "0pqagwqrp6sw7l5hcbjs308wqnxyslnpr7x8svs58dlkzn70255q";
};
linux = fetchzip {
url = "https://dl.google.com/android/repository/android-ndk-${ndk-version}-linux-x86_64.zip";
sha256 = "168dbhk7cvrri1b4jwskjqm5mj14cg6px7y7ycz4g9m8byqvqjhf";
};
};
in stdenv.mkDerivation rec {
name = "android-ndk";
version = ndk-version;
src = if stdenv.isLinux then archives.linux else archives.macosx;
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
mkdir $out
cp -rv . $out
'';
meta = {
description = "The Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C++. For certain types of apps, this can help you reuse code libraries written in those languages.";
homepage = https://developer.android.com/ndk;
license = stdenv.lib.licenses.asl20;
maintainers = [ stdenv.lib.maintainers.pombeirp ];
platforms = stdenv.lib.platforms.unix;
};
}

View File

@ -0,0 +1,24 @@
{ stdenv, pkgs }:
with pkgs;
with stdenv;
let
android-ndk = callPackage ./android-ndk { };
in
{
buildInputs = [
android-ndk
openjdk
];
shellHook = ''
export JAVA_HOME="${openjdk}"
export ANDROID_HOME=~/.status/Android/Sdk
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_NDK_ROOT="${android-ndk}"
export ANDROID_NDK_HOME="${android-ndk}"
export ANDROID_NDK="${android-ndk}"
export PATH="$ANDROID_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$PATH"
'';
}

View File

@ -1,2 +1,3 @@
extra-substituters = https://nix-cache.status.im/
trusted-public-keys = nix-cache.status.im-1:x/93lOfLU+duPplwMSBR+OlY4+mo+dCN7n0mr4oPwgY= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
connect-timeout = 10

View File

@ -62,8 +62,7 @@ fi
setup_header "Installing requirements..."
install_nix && \
install_android_sdk && \
install_android_ndk || \
install_android_sdk || \
exit $?
####