Skip to content

Commit e9b1fa9

Browse files
committed
Import dist-build/android-aar.sh readability
1 parent 4d96d50 commit e9b1fa9

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

dist-build/android-aar.sh

+35-12
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,47 @@
77
SODIUM_VERSION="1.0.21.0"
88

99
if [ -z "$ANDROID_NDK_HOME" ]; then
10-
echo "You should probably set ANDROID_NDK_HOME to the directory containing"
11-
echo "the Android NDK."
10+
echo "ANDROID_NDK_HOME must be set to the directory containing the Android NDK."
11+
exit 1
12+
fi
13+
14+
if [ ! -f "${ANDROID_NDK_HOME}/ndk-build" ]; then
15+
echo "The ANDROID_NDK_HOME directory does not contain an 'ndk-build' file."
16+
exit 1
17+
fi
18+
19+
if [ ! -d "${ANDROID_NDK_HOME}/toolchains" ]; then
20+
echo "The ANDROID_NDK_HOME directory does not contain a 'toolchains' directory."
1221
exit 1
1322
fi
1423

1524
if [ ! -f "${ANDROID_NDK_HOME}/source.properties" ]; then
16-
sp=$(find "${ANDROID_NDK_HOME}" -depth 2 -type f -name source.properties | head -n1)
17-
if [ -n "$sp" ]; then
18-
export ANDROID_NDK_HOME=$(dirname "$sp")
19-
else
20-
echo "The ANDROID_NDK_HOME directory does not contain a 'source.properties' file."
21-
exit 1
22-
fi
25+
echo "The ANDROID_NDK_HOME directory does not contain a 'source.properties' file."
26+
exit 1
2327
fi
2428

2529
NDK_VERSION=$(grep "Pkg.Revision = " <"${ANDROID_NDK_HOME}/source.properties" | cut -f 2 -d '=' | cut -f 2 -d' ' | cut -f 1 -d'.')
2630
DEST_PATH=$(mktemp -d)
2731

2832
if [ -z "$NDK_PLATFORM" ]; then
2933
export NDK_PLATFORM="android-21"
30-
echo "Compiling for default platform: [${NDK_PLATFORM}] - That can be changed by setting an NDK_PLATFORM environment variable."
34+
echo "Compiling for default platform: [${NDK_PLATFORM}]"
35+
echo "That can be changed by setting an NDK_PLATFORM environment variable."
3136
fi
3237

3338
SDK_VERSION=$(echo "$NDK_PLATFORM" | cut -f2 -d"-")
39+
if [ -z "$NDK_VERSION" ]; then
40+
echo "Failed to determine the NDK version."
41+
exit 1
42+
fi
43+
if [ -z "$SDK_VERSION" ]; then
44+
echo "Failed to determine the SDK version."
45+
exit 1
46+
fi
47+
echo "NDK version: [$NDK_VERSION]"
48+
echo "SDK version: [$SDK_VERSION]"
49+
50+
echo
3451

3552
if which zip >/dev/null; then
3653
echo "The 'zip' command is installed."
@@ -41,6 +58,8 @@ fi
4158

4259
cd "$(dirname "$0")/../" || exit
4360

61+
trap 'kill -TERM -$$' INT
62+
4463
make_abi_json() {
4564
echo "{\"abi\":\"${NDK_ARCH}\",\"api\":${SDK_VERSION},\"ndk\":${NDK_VERSION},\"stl\":\"none\"}" >"$1/abi.json"
4665
}
@@ -134,7 +153,9 @@ zip -9 -r "$AAR_PATH" META-INF prefab AndroidManifest.xml
134153
cd .. || exit
135154
rm -r "$DEST_PATH"
136155

137-
echo "Congrats you have built an AAR containing libsodium!
156+
echo "
157+
158+
Congrats you have built an AAR containing libsodium!
138159
The build used a min Android SDK of version $SDK_VERSION
139160
You can build for a different SDK version by specifying NDK_PLATFORM=\"android-{SDK_VERSION}\"
140161
as an environment variable before running this script but the defaults should be fine.
@@ -168,4 +189,6 @@ gradle or cmake (as set by default for Android Studio projects):
168189
- 'sodium' for the full shared library,
169190
- 'sodium-static' for the full static library
170191
- 'sodium-minimal' for the minimal shared library, or
171-
- 'sodium-minimal-static' for the minimal static library."
192+
- 'sodium-minimal-static' for the minimal static library.
193+
194+
"

dist-build/android-build.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export NDK_API_VERSION="$(echo "$NDK_PLATFORM" | sed 's/^android-//')"
1010
export NDK_API_VERSION_COMPAT="$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')"
1111

1212
if [ -z "$ANDROID_NDK_HOME" ]; then
13-
echo "You should probably set ANDROID_NDK_HOME to the directory containing"
14-
echo "the Android NDK."
13+
echo "ANDROID_NDK_HOME must be set to the directory containing the Android NDK."
1514
exit 1
1615
fi
1716

@@ -61,6 +60,10 @@ fi
6160
--prefix="${PREFIX}" \
6261
--with-sysroot="${TOOLCHAIN_DIR}/sysroot" || exit 1
6362

63+
if [ -z "$NDK_PLATFORM" ]; then
64+
echo "Aborting"
65+
exit 1
66+
fi
6467
if [ "$NDK_PLATFORM" != "$NDK_PLATFORM_COMPAT" ]; then
6568
grep -E '^#define ' config.log | sort -u >config-def-compat.log
6669
echo

0 commit comments

Comments
 (0)