Use Android SDK from nixpkgs instead of downloading

This commit is contained in:
Pedro Pombeiro 2019-04-11 14:48:53 +02:00
parent 89f34a7707
commit 8e6b8b1ff1
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
7 changed files with 91 additions and 129 deletions

View File

@ -48,7 +48,7 @@ clean: ##@prepare Remove all output folders
clean-nix: SHELL := /bin/sh clean-nix: SHELL := /bin/sh
clean-nix: ##@prepare Remove complete nix setup clean-nix: ##@prepare Remove complete nix setup
sudo rm -rf /nix ~/.cache/nix sudo rm -rf /nix ~/.nix-profile ~/.nix-defexpr ~/.nix-channels ~/.cache/nix ~/.status
shell: ##@prepare Enter into a pre-configured shell shell: ##@prepare Enter into a pre-configured shell
ifndef IN_NIX_SHELL ifndef IN_NIX_SHELL

View File

@ -1,6 +1,5 @@
# target-os = [ 'windows' 'linux' 'macos' 'darwin' 'android' 'ios' ]
{ system ? builtins.currentSystem { system ? builtins.currentSystem
, config ? {}, overlays ? [] , config ? { android_sdk.accept_license = true; }, overlays ? []
, pkgs ? (import <nixpkgs> { inherit system config overlays; }) , pkgs ? (import <nixpkgs> { inherit system config overlays; })
, target-os }: , target-os }:
@ -27,8 +26,8 @@ with pkgs;
# TODO: Try to use stdenv for iOS. The problem is with building iOS as the build is trying to pass parameters to Apple's ld that are meant for GNU's ld (e.g. -dynamiclib) # TODO: Try to use stdenv for iOS. The problem is with building iOS as the build is trying to pass parameters to Apple's ld that are meant for GNU's ld (e.g. -dynamiclib)
_stdenv = stdenvNoCC; _stdenv = stdenvNoCC;
statusDesktop = callPackage ./nix/desktop { inherit target-os; stdenv = _stdenv; }; statusDesktop = callPackage ./nix/desktop { inherit target-os; stdenv = _stdenv; };
statusMobile = callPackage ./nix/mobile { inherit target-os status-go; androidPkgs = androidComposition; stdenv = _stdenv; }; statusMobile = callPackage ./nix/mobile { inherit target-os config status-go; stdenv = _stdenv; };
status-go = callPackage ./nix/status-go { inherit (xcodeenv) composeXcodeWrapper; inherit xcodewrapperArgs; androidPkgs = androidComposition; }; status-go = callPackage ./nix/status-go { inherit (xcodeenv) composeXcodeWrapper; inherit (statusMobile) xcodewrapperArgs; androidPkgs = statusMobile.androidComposition; };
nodejs' = pkgs.nodejs-10_x; nodejs' = pkgs.nodejs-10_x;
yarn' = yarn.override { nodejs = nodejs'; }; yarn' = yarn.override { nodejs = nodejs'; };
nodeInputs = import ./nix/global-node-packages/output { nodeInputs = import ./nix/global-node-packages/output {
@ -41,29 +40,6 @@ with pkgs;
python27 # for e.g. gyp python27 # for e.g. gyp
yarn' yarn'
] ++ (map (x: nodeInputs."${x}") (builtins.attrNames nodeInputs)); ] ++ (map (x: nodeInputs."${x}") (builtins.attrNames nodeInputs));
xcodewrapperArgs = {
version = "10.1";
};
xcodeWrapper = xcodeenv.composeXcodeWrapper xcodewrapperArgs;
androidComposition = androidenv.composeAndroidPackages {
toolsVersion = "26.1.1";
platformToolsVersion = "28.0.2";
buildToolsVersions = [ "28.0.3" ];
includeEmulator = false;
platformVersions = [ "26" "27" ];
includeSources = false;
includeDocs = false;
includeSystemImages = false;
systemImageTypes = [ "default" ];
abiVersions = [ "armeabi-v7a" ];
lldbVersions = [ "2.0.2558144" ];
cmakeVersions = [ "3.6.4111459" ];
includeNDK = true;
ndkVersion = "19.2.5345600";
useGoogleAPIs = false;
useGoogleTVAddOns = false;
includeExtras = [ "extras;android;m2repository" "extras;google;m2repository" ];
};
in _stdenv.mkDerivation rec { in _stdenv.mkDerivation rec {
name = "status-react-build-env"; name = "status-react-build-env";

63
nix/mobile/android.nix Normal file
View File

@ -0,0 +1,63 @@
{ config, stdenv, pkgs }:
with pkgs;
with stdenv;
let
gradle = gradle_4_10;
androidComposition = androidenv.composeAndroidPackages {
toolsVersion = "26.1.1";
platformToolsVersion = "28.0.2";
buildToolsVersions = [ "28.0.3" ];
includeEmulator = false;
platformVersions = [ "28" ];
includeSources = false;
includeDocs = false;
includeSystemImages = false;
systemImageTypes = [ "default" ];
abiVersions = [ "armeabi-v7a" ];
lldbVersions = [ "2.0.2558144" ];
cmakeVersions = [ "3.6.4111459" ];
includeNDK = true;
ndkVersion = "19.2.5345600";
useGoogleAPIs = false;
useGoogleTVAddOns = false;
includeExtras = [ "extras;android;m2repository" "extras;google;m2repository" ];
};
in
{
inherit androidComposition;
buildInputs = [ openjdk gradle ];
shellHook = ''
export JAVA_HOME="${openjdk}"
export ANDROID_HOME=~/.status/Android/Sdk
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_NDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk/ndk-bundle"
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"
'' +
## We need to make a writeable copy of the Android SDK so that we can accept the license (which causes files to be written to the SDK folders)
## since the nix store is immutable by nature, we can't license the SDK from there.
''
if ! [ -d $ANDROID_HOME ]; then
echo "=> pulling the Android SDK out of the nix store and into a writeable directory"
mkdir -p $ANDROID_HOME
cp -rL ${androidComposition.androidsdk}/bin $ANDROID_HOME
cp -rL ${androidComposition.androidsdk}/libexec/android-sdk/* $ANDROID_HOME/
chmod -R 755 $ANDROID_HOME/
'' + lib.optionalString config.android_sdk.accept_license ''
echo "=> accepting Android SDK licenses"
pushd $ANDROID_HOME
yes | $PWD/bin/sdkmanager --licenses || if [ $? -ne '141' ]; then exit $?; fi; #Captures SIGPIPE 141 error but still allow repeating "y" to accept all licenses
popd
'' +
''
echo "=> generating keystore"
$PWD/scripts/generate-keystore.sh
fi
'';
}

View File

@ -1,4 +1,4 @@
{ stdenv, pkgs, target-os ? "all", status-go, androidPkgs }: { config, stdenv, pkgs, target-os ? "all", status-go }:
with pkgs; with pkgs;
with stdenv; with stdenv;
@ -13,24 +13,21 @@ let
"ios" = true; "ios" = true;
"all" = true; "all" = true;
}.${target-os} or false; }.${target-os} or false;
xcodewrapperArgs = {
version = "10.1";
};
android = callPackage ./android.nix { inherit config; };
in in
{ {
inherit (android) androidComposition;
inherit xcodewrapperArgs;
buildInputs = buildInputs =
lib.optionals targetAndroid [ lib.optional targetAndroid android.buildInputs;
openjdk gradle
];
shellHook = shellHook =
lib.optionalString targetIOS '' lib.optionalString targetIOS ''
export RCTSTATUS_FILEPATH=${status-go}/lib/ios/Statusgo.framework export RCTSTATUS_FILEPATH=${status-go}/lib/ios/Statusgo.framework
'' + '' +
lib.optionalString targetAndroid '' lib.optionalString targetAndroid android.shellHook;
export JAVA_HOME="${openjdk}"
export ANDROID_HOME=~/.status/Android/Sdk
export ANDROID_SDK_ROOT="$ANDROID_HOME"
export ANDROID_NDK_ROOT="${androidPkgs.ndk-bundle}/libexec/android-sdk/ndk-bundle"
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"
'';
} }

View File

@ -16,6 +16,8 @@ if ! command -v "nix" >/dev/null 2>&1; then
else else
echo -e "${GREEN}Setting up environment...${NC}" echo -e "${GREEN}Setting up environment...${NC}"
./scripts/setup ./scripts/setup
. ~/.nix-profile/etc/profile.d/nix.sh
fi fi
fi fi

View File

@ -1,84 +0,0 @@
#!/usr/bin/env bash
GIT_ROOT=$(git rev-parse --show-toplevel)
function download_url() {
if program_exists "aria2c"; then
aria2c --max-connection-per-server=16 --split=16 --dir="$1" -o "$2" "$3"
else
wget --show-progress --output-document="$1/$2" "$3"
fi
}
function install_nix() {
if ! program_exists nix; then
local required_version=$(toolversion nix)
NIX_INSTALLER_NO_MODIFY_PROFILE=1 bash <(curl https://nixos.org/releases/nix/nix-${required_version}/install) --no-daemon
if [ $? -eq 0 ]; then
echo -e "${YELLOW}**********************************************************************************************************"
echo "The Nix package manager was successfully installed."
echo -e "**********************************************************************************************************${NC}"
else
echo "Please see https://nixos.org/nix/manual/#chap-installation"
fi
exit
fi
}
function install_android_sdk() {
if [ -z "$ANDROID_SDK_ROOT" ]; then
return 0
fi
if [ -d "$ANDROID_SDK_ROOT" ]; then
cecho "@green[[Android SDK already installed.]]"
else
local required_version=$(toolversion android-sdk)
mkdir -p $ANDROID_SDK_ROOT
cecho "@cyan[[Downloading Android SDK.]]"
local PLATFORM=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
download_url . sdk-tools-${PLATFORM}.zip https://dl.google.com/android/repository/sdk-tools-${PLATFORM}-${required_version}.zip && \
cecho "@cyan[[Extracting Android SDK to $ANDROID_SDK_ROOT.]]" && \
unzip -q -o ./sdk-tools-${PLATFORM}.zip -d "$ANDROID_SDK_ROOT" && \
rm -f ./sdk-tools-${PLATFORM}.zip && \
cecho "@blue[[Android SDK installation completed in $ANDROID_SDK_ROOT.]]" || \
exit $?
fi
[ $? -eq 0 ] && use_android_sdk
return 0
}
function dependency_setup() {
cecho "@b@blue[[\$ $@]]"
echo
cd "$(repo_path)"
eval "$@" || (cecho "@b@red[[Error running dependency install '$@']]" && exit 1)
echo
echo " + done"
echo
}
function use_android_sdk() {
if [ -d "$ANDROID_SDK_ROOT" ]; then
local ANDROID_BUILD_TOOLS_VERSION=$(toolversion android-sdk-build-tools)
local ANDROID_PLATFORM_VERSION=$(toolversion android-sdk-platform)
touch ~/.android/repositories.cfg
echo y | sdkmanager "platform-tools" "build-tools;$ANDROID_BUILD_TOOLS_VERSION" "platforms;$ANDROID_PLATFORM_VERSION"
yes | sdkmanager --licenses
else
local _docUrl="https://status.im/build_status/"
cecho "@yellow[[ANDROID_SDK_ROOT environment variable not defined, please install the Android SDK.]]"
cecho "@yellow[[(see $_docUrl).]]"
echo
exit 1
fi
scripts/generate-keystore.sh
}

View File

@ -13,7 +13,6 @@ source "$_current_dir/lib/setup/path-support.sh"
source_lib "output.sh" source_lib "output.sh"
source_lib "packages.sh" source_lib "packages.sh"
source_lib "platform.sh" source_lib "platform.sh"
source_lib "installers.sh"
exit_unless_os_supported exit_unless_os_supported
@ -46,9 +45,18 @@ fi
#### ####
setup_header "Installing requirements..." setup_header "Installing requirements..."
install_nix && \ if ! program_exists nix; then
install_android_sdk || \ required_version=$(toolversion nix)
exit $? NIX_INSTALLER_NO_MODIFY_PROFILE=1 bash <(curl https://nixos.org/releases/nix/nix-${required_version}/install) --no-daemon
if [ $? -eq 0 ]; then
echo -e "${YELLOW}**********************************************************************************************************"
echo "The Nix package manager was successfully installed."
echo -e "**********************************************************************************************************${NC}"
else
echo "Please see https://nixos.org/nix/manual/#chap-installation"
exit
fi
fi
#### ####
setup_complete setup_complete