Create androidenv package with accepted license so build can run with --pure

This commit is contained in:
Pedro Pombeiro 2019-04-29 18:33:40 +02:00
parent 33621aec7c
commit b575f5f6a5
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
8 changed files with 49 additions and 53 deletions

10
.gitignore vendored
View File

@ -65,13 +65,6 @@ shim.js
# Desktop build
index.desktop.js
# Docker
#
docker/*/scripts/
docker/*/*.zip
docker/*/*.run
docker/*/nvm_install.sh
# Generated by lein voom
#
/pom.xml
@ -166,3 +159,6 @@ conan.cmake
# Env
.env.bkp
# nix
/.ran-setup

View File

@ -16,7 +16,7 @@ def getToolVersion(name) {
}
def nix_sh(cmd) {
def isPure = env.TARGET_OS == 'linux'
def isPure = env.TARGET_OS == 'linux' || env.TARGET_OS == 'android'
def pureFlag = isPure ? '--pure' : ''
sh """

View File

@ -24,6 +24,7 @@ let
useGoogleTVAddOns = false;
includeExtras = [ "extras;android;m2repository" "extras;google;m2repository" ];
};
licensedAndroidEnv = callPackage ./licensed-android-sdk.nix { inherit androidComposition; };
in
{
@ -32,32 +33,13 @@ in
buildInputs = [ openjdk gradle ];
shellHook = ''
export JAVA_HOME="${openjdk}"
export ANDROID_HOME=~/.status/Android/Sdk
export ANDROID_HOME=${licensedAndroidEnv}
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
$(git rev-parse --show-toplevel)/scripts/generate-keystore.sh
'';
}

View File

@ -0,0 +1,23 @@
{ config, stdenv, pkgs, androidComposition }:
with pkgs;
stdenv.mkDerivation rec {
name = "licensed-android-sdk";
version = "licensed";
phases = [ "installPhase" ];
installPhase = ''
mkdir -p $out/libexec/android-sdk
ln -s "${androidComposition.androidsdk}/bin" $out/bin
for d in ${androidComposition.androidsdk}/libexec/android-sdk/*; do
ln -s $d $out/$(basename $d)
done
'' + stdenv.lib.optionalString config.android_sdk.accept_license ''
mkdir -p $out/licenses
echo -e "\n601085b94cd77f0b54ff86406957099ebe79c4d6" > "$out/licenses/android-googletv-license"
echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$out/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$out/licenses/android-sdk-preview-license"
echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "$out/licenses/intel-android-extra-license"
echo -e "\n33b6a2b64607f11b759f320ef9dff4ae5c47d97a" > "$out/licenses/google-gdk-license"
'';
}

View File

@ -22,12 +22,16 @@ if ! command -v "nix" >/dev/null 2>&1; then
fi
if command -v "nix" >/dev/null 2>&1; then
echo -e "${GREEN}Configuring Nix shell for target '${TARGET_OS:=all}'...${NC}"
if [[ $@ == "ENTER_NIX_SHELL" ]]; then
echo -e "${GREEN}Configuring Nix shell for target '${TARGET_OS:=all}'...${NC}"
exec nix-shell --show-trace --argstr target-os ${TARGET_OS}
else
is_pure=''
[ "${TARGET_OS}" == 'linux' ] && is_pure='--pure'
if [ "${TARGET_OS}" == 'linux' ] || [ "${TARGET_OS}" == 'android' ]; then
is_pure='--pure'
pure_desc='pure '
fi
echo -e "${GREEN}Configuring ${pure_desc}Nix shell for target '${TARGET_OS:=all}'...${NC}"
exec nix-shell ${is_pure} --show-trace --argstr target-os ${TARGET_OS} --run "$@"
fi
fi

View File

@ -14,10 +14,10 @@ STATUS_RELEASE_STORE_PASSWORD=$(property_gradle 'STATUS_RELEASE_STORE_PASSWORD')
STATUS_RELEASE_KEY_ALIAS=$(property_gradle 'STATUS_RELEASE_KEY_ALIAS')
STATUS_RELEASE_KEY_PASSWORD=$(property_gradle 'STATUS_RELEASE_KEY_PASSWORD')
[[ -e "$STORE_FILE" ]] && echo "Keystore $STORE_FILE already exists, please manually remove it if you want to regenerate." && exit 0
[[ -e "$STORE_FILE" ]] && exit 0
echo "Generating keystore $STORE_FILE"
keydirname="$( dirname "$STORE_FILE" )"
[ -d $keydirname ] || mkdir -p $keydirname
keytool -genkey -v -keystore ${STORE_FILE} -keyalg RSA -keysize 2048 -validity 10000 -alias ${STATUS_RELEASE_KEY_ALIAS} \
keytool -genkey -v -keystore ${STORE_FILE} -keyalg RSA -keysize 2048 -validity 10000 -alias ${STATUS_RELEASE_KEY_ALIAS} \
-storepass ${STATUS_RELEASE_STORE_PASSWORD} -keypass ${STATUS_RELEASE_KEY_PASSWORD} -dname "CN=, OU=, O=, L=, S=, C="

View File

@ -38,22 +38,9 @@ if [ -z "$IN_NIX_SHELL" ]; then
fi
fi
if [ "$PLATFORM" == 'android' ]; then
if [ ! -d $ANDROID_SDK_ROOT ]; then
echo -e "${GREEN}SDK setup not complete, please run 'scripts/setup'!${NC}"
exit 1
fi
if [ ! -d $ANDROID_NDK_ROOT ]; then
echo -e "${GREEN}NDK setup not complete, please run 'scripts/setup'!${NC}"
exit 1
fi
elif [ "$PLATFORM" == 'ios' ] && [ "$(uname)" != "Darwin" ]; then
if [ "$PLATFORM" == 'ios' ] && [ "$(uname)" != "Darwin" ]; then
echo -e "${RED}iOS builds are only possible on macOS hosts${NC}"
exit 1
fi
if [[ $PLATFORM == 'setup' ]]; then
echo -e "${YELLOW}Finished! Please close your terminal, reopen a new one and type 'nix-shell' before building Status.${NC}"
else
echo -e "${GREEN}Finished!${NC}"
fi
echo -e "${GREEN}Finished!${NC}"

View File

@ -18,7 +18,9 @@ in _mkShell {
# utilities
bash
curl
file
git
gnumake
jq
ncurses
lsof # used in scripts/start-react-native.sh
@ -31,11 +33,13 @@ in _mkShell {
shellHook =
''
set -e
'' +
projectDeps.shellHook +
''
if [ -n "$ANDROID_SDK_ROOT" ] && [ ! -d "$ANDROID_SDK_ROOT" ]; then
./scripts/setup # we assume that if the Android SDK dir does not exist, setup script needs to be run
${projectDeps.shellHook}
STATUS_REACT_HOME=$(git rev-parse --show-toplevel)
if [ ! -f $STATUS_REACT_HOME/.ran-setup ]; then
$STATUS_REACT_HOME/scripts/setup
touch $STATUS_REACT_HOME/.ran-setup
fi
set +e
'';