xref: /freebsd/contrib/unbound/contrib/android/install_ndk.sh (revision a90b9d0159070121c221b966469c3e36d912bf82)
1#!/usr/bin/env bash
2
3if [ -z "$ANDROID_SDK_ROOT" ]; then
4    echo "ERROR: ANDROID_SDK_ROOT is not a valid path. Please set it."
5    echo "SDK root is $ANDROID_SDK_ROOT"
6    exit 1
7fi
8
9if [ -z "$ANDROID_NDK_ROOT" ]; then
10    echo "ERROR: ANDROID_NDK_ROOT is not a valid path. Please set it."
11    echo "NDK root is $ANDROID_NDK_ROOT"
12    exit 1
13fi
14
15echo "Using ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT"
16echo "Using ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
17
18echo "Downloading SDK"
19if ! curl -L -k -s -o "$HOME/android-sdk.zip" https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip;
20then
21    echo "Failed to download SDK"
22    exit 1
23fi
24
25echo "Downloading NDK"
26if ! curl -L -k -s -o "$HOME/android-ndk.zip" https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip;
27then
28    echo "Failed to download NDK"
29    exit 1
30fi
31
32echo "Unpacking SDK to $ANDROID_SDK_ROOT"
33if ! unzip -qq "$HOME/android-sdk.zip" -d "$ANDROID_SDK_ROOT";
34then
35    echo "Failed to unpack SDK"
36    exit 1
37fi
38
39echo "Unpacking NDK to $ANDROID_NDK_ROOT"
40if ! unzip -qq "$HOME/android-ndk.zip" -d "$HOME";
41then
42    echo "Failed to unpack NDK"
43    exit 1
44fi
45
46if ! mv "$HOME/android-ndk-r20b" "$ANDROID_NDK_ROOT";
47then
48    echo "Failed to move $HOME/android-ndk-r20b to $ANDROID_NDK_ROOT"
49    exit 1
50fi
51
52rm -f "$HOME/android-sdk.zip"
53rm -f "$HOME/android-ndk.zip"
54
55# https://stackoverflow.com/a/47028911/608639
56touch "$ANDROID_SDK_ROOT/repositories.cfg"
57
58echo "Finished installing SDK and NDK"
59
60exit 0
61