Skip to content

Commit b575f5f

Browse files
author
Pedro Pombeiro
committed
Create androidenv package with accepted license so build can run with --pure
1 parent 33621ae commit b575f5f

8 files changed

Lines changed: 49 additions & 53 deletions

File tree

.gitignore

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ shim.js
6565
# Desktop build
6666
index.desktop.js
6767

68-
# Docker
69-
#
70-
docker/*/scripts/
71-
docker/*/*.zip
72-
docker/*/*.run
73-
docker/*/nvm_install.sh
74-
7568
# Generated by lein voom
7669
#
7770
/pom.xml
@@ -166,3 +159,6 @@ conan.cmake
166159

167160
# Env
168161
.env.bkp
162+
163+
# nix
164+
/.ran-setup

ci/utils.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def getToolVersion(name) {
1616
}
1717

1818
def nix_sh(cmd) {
19-
def isPure = env.TARGET_OS == 'linux'
19+
def isPure = env.TARGET_OS == 'linux' || env.TARGET_OS == 'android'
2020
def pureFlag = isPure ? '--pure' : ''
2121

2222
sh """

nix/mobile/android.nix

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let
2424
useGoogleTVAddOns = false;
2525
includeExtras = [ "extras;android;m2repository" "extras;google;m2repository" ];
2626
};
27+
licensedAndroidEnv = callPackage ./licensed-android-sdk.nix { inherit androidComposition; };
2728

2829
in
2930
{
@@ -32,32 +33,13 @@ in
3233
buildInputs = [ openjdk gradle ];
3334
shellHook = ''
3435
export JAVA_HOME="${openjdk}"
35-
export ANDROID_HOME=~/.status/Android/Sdk
36+
export ANDROID_HOME=${licensedAndroidEnv}
3637
export ANDROID_SDK_ROOT="$ANDROID_HOME"
3738
export ANDROID_NDK_ROOT="${androidComposition.androidsdk}/libexec/android-sdk/ndk-bundle"
3839
export ANDROID_NDK_HOME="$ANDROID_NDK_ROOT"
3940
export ANDROID_NDK="$ANDROID_NDK_ROOT"
4041
export PATH="$ANDROID_HOME/bin:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$PATH"
41-
'' +
42-
## 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)
43-
## since the nix store is immutable by nature, we can't license the SDK from there.
44-
''
45-
if ! [ -d $ANDROID_HOME ]; then
46-
echo "=> pulling the Android SDK out of the nix store and into a writeable directory"
4742
48-
mkdir -p $ANDROID_HOME
49-
cp -rL ${androidComposition.androidsdk}/bin $ANDROID_HOME
50-
cp -rL ${androidComposition.androidsdk}/libexec/android-sdk/* $ANDROID_HOME/
51-
chmod -R 755 $ANDROID_HOME/
52-
'' + lib.optionalString config.android_sdk.accept_license ''
53-
echo "=> accepting Android SDK licenses"
54-
pushd $ANDROID_HOME
55-
yes | $PWD/bin/sdkmanager --licenses || if [ $? -ne '141' ]; then exit $?; fi; #Captures SIGPIPE 141 error but still allow repeating "y" to accept all licenses
56-
popd
57-
'' +
58-
''
59-
echo "=> generating keystore"
60-
$PWD/scripts/generate-keystore.sh
61-
fi
43+
$(git rev-parse --show-toplevel)/scripts/generate-keystore.sh
6244
'';
6345
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{ config, stdenv, pkgs, androidComposition }:
2+
3+
with pkgs;
4+
5+
stdenv.mkDerivation rec {
6+
name = "licensed-android-sdk";
7+
version = "licensed";
8+
phases = [ "installPhase" ];
9+
installPhase = ''
10+
mkdir -p $out/libexec/android-sdk
11+
ln -s "${androidComposition.androidsdk}/bin" $out/bin
12+
for d in ${androidComposition.androidsdk}/libexec/android-sdk/*; do
13+
ln -s $d $out/$(basename $d)
14+
done
15+
'' + stdenv.lib.optionalString config.android_sdk.accept_license ''
16+
mkdir -p $out/licenses
17+
echo -e "\n601085b94cd77f0b54ff86406957099ebe79c4d6" > "$out/licenses/android-googletv-license"
18+
echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$out/licenses/android-sdk-license"
19+
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$out/licenses/android-sdk-preview-license"
20+
echo -e "\nd975f751698a77b662f1254ddbeed3901e976f5a" > "$out/licenses/intel-android-extra-license"
21+
echo -e "\n33b6a2b64607f11b759f320ef9dff4ae5c47d97a" > "$out/licenses/google-gdk-license"
22+
'';
23+
}

nix/shell.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ if ! command -v "nix" >/dev/null 2>&1; then
2222
fi
2323

2424
if command -v "nix" >/dev/null 2>&1; then
25-
echo -e "${GREEN}Configuring Nix shell for target '${TARGET_OS:=all}'...${NC}"
2625
if [[ $@ == "ENTER_NIX_SHELL" ]]; then
26+
echo -e "${GREEN}Configuring Nix shell for target '${TARGET_OS:=all}'...${NC}"
2727
exec nix-shell --show-trace --argstr target-os ${TARGET_OS}
2828
else
2929
is_pure=''
30-
[ "${TARGET_OS}" == 'linux' ] && is_pure='--pure'
30+
if [ "${TARGET_OS}" == 'linux' ] || [ "${TARGET_OS}" == 'android' ]; then
31+
is_pure='--pure'
32+
pure_desc='pure '
33+
fi
34+
echo -e "${GREEN}Configuring ${pure_desc}Nix shell for target '${TARGET_OS:=all}'...${NC}"
3135
exec nix-shell ${is_pure} --show-trace --argstr target-os ${TARGET_OS} --run "$@"
3236
fi
3337
fi

scripts/generate-keystore.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ STATUS_RELEASE_STORE_PASSWORD=$(property_gradle 'STATUS_RELEASE_STORE_PASSWORD')
1414
STATUS_RELEASE_KEY_ALIAS=$(property_gradle 'STATUS_RELEASE_KEY_ALIAS')
1515
STATUS_RELEASE_KEY_PASSWORD=$(property_gradle 'STATUS_RELEASE_KEY_PASSWORD')
1616

17-
[[ -e "$STORE_FILE" ]] && echo "Keystore $STORE_FILE already exists, please manually remove it if you want to regenerate." && exit 0
17+
[[ -e "$STORE_FILE" ]] && exit 0
1818

1919
echo "Generating keystore $STORE_FILE"
2020
keydirname="$( dirname "$STORE_FILE" )"
2121
[ -d $keydirname ] || mkdir -p $keydirname
22-
keytool -genkey -v -keystore ${STORE_FILE} -keyalg RSA -keysize 2048 -validity 10000 -alias ${STATUS_RELEASE_KEY_ALIAS} \
22+
keytool -genkey -v -keystore ${STORE_FILE} -keyalg RSA -keysize 2048 -validity 10000 -alias ${STATUS_RELEASE_KEY_ALIAS} \
2323
-storepass ${STATUS_RELEASE_STORE_PASSWORD} -keypass ${STATUS_RELEASE_KEY_PASSWORD} -dname "CN=, OU=, O=, L=, S=, C="

scripts/run-environment-check.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,9 @@ if [ -z "$IN_NIX_SHELL" ]; then
3838
fi
3939
fi
4040

41-
if [ "$PLATFORM" == 'android' ]; then
42-
if [ ! -d $ANDROID_SDK_ROOT ]; then
43-
echo -e "${GREEN}SDK setup not complete, please run 'scripts/setup'!${NC}"
44-
exit 1
45-
fi
46-
if [ ! -d $ANDROID_NDK_ROOT ]; then
47-
echo -e "${GREEN}NDK setup not complete, please run 'scripts/setup'!${NC}"
48-
exit 1
49-
fi
50-
elif [ "$PLATFORM" == 'ios' ] && [ "$(uname)" != "Darwin" ]; then
41+
if [ "$PLATFORM" == 'ios' ] && [ "$(uname)" != "Darwin" ]; then
5142
echo -e "${RED}iOS builds are only possible on macOS hosts${NC}"
5243
exit 1
5344
fi
5445

55-
if [[ $PLATFORM == 'setup' ]]; then
56-
echo -e "${YELLOW}Finished! Please close your terminal, reopen a new one and type 'nix-shell' before building Status.${NC}"
57-
else
58-
echo -e "${GREEN}Finished!${NC}"
59-
fi
46+
echo -e "${GREEN}Finished!${NC}"

shell.nix

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ in _mkShell {
1818
# utilities
1919
bash
2020
curl
21+
file
2122
git
23+
gnumake
2224
jq
2325
ncurses
2426
lsof # used in scripts/start-react-native.sh
@@ -31,11 +33,13 @@ in _mkShell {
3133
shellHook =
3234
''
3335
set -e
34-
'' +
35-
projectDeps.shellHook +
36-
''
37-
if [ -n "$ANDROID_SDK_ROOT" ] && [ ! -d "$ANDROID_SDK_ROOT" ]; then
38-
./scripts/setup # we assume that if the Android SDK dir does not exist, setup script needs to be run
36+
37+
${projectDeps.shellHook}
38+
39+
STATUS_REACT_HOME=$(git rev-parse --show-toplevel)
40+
if [ ! -f $STATUS_REACT_HOME/.ran-setup ]; then
41+
$STATUS_REACT_HOME/scripts/setup
42+
touch $STATUS_REACT_HOME/.ran-setup
3943
fi
4044
set +e
4145
'';

0 commit comments

Comments
 (0)