diff --git a/dist-build/android-aar.sh b/dist-build/android-aar.sh index 7f4df71d..0f7f1084 100755 --- a/dist-build/android-aar.sh +++ b/dist-build/android-aar.sh @@ -2,13 +2,20 @@ # Create an AAR with libsodium in all combinations of static | shared | minimal | full. # -# The x86 static library will not work due to text relocation rules, so static x86 versions are limited to shared libraries. # To simplify linking, library variants have distinct names: sodium, sodium-static, sodium-minimal and sodium-minimal-static. SODIUM_VERSION="1.0.21.0" NDK_VERSION=$(grep "Pkg.Revision = " <"${ANDROID_NDK_HOME}/source.properties" | cut -f 2 -d '=' | cut -f 2 -d' ' | cut -f 1 -d'.') DEST_PATH=$(mktemp -d) +if [ -z "$NDK_PLATFORM" ]; then + export NDK_PLATFORM="android-21" + echo "Compiling for default platform: [${NDK_PLATFORM}] - That can be changed by setting an NDK_PLATFORM environment variable." +fi + +SDK_VERSION=$( echo "$NDK_PLATFORM" | cut -f2 -d"-" ) + + if which zip >/dev/null; then echo "The 'zip' command is installed." else @@ -28,7 +35,7 @@ make_prefab_json() { make_manifest() { echo " - + " >"${1}/AndroidManifest.xml" } @@ -60,11 +67,7 @@ make_prefab_structure() { mkdir "$DEST_PATH/${variant}/libs/android.${arch}" mkdir "$DEST_PATH/${variant}/libs/android.${arch}/include" NDK_ARCH="$arch" - if [ $arch = "arm64-v8a" ] || [ $arch = "x86_64" ]; then - SDK_VERSION="21" - else - SDK_VERSION="19" - fi + make_abi_json "$DEST_PATH/${variant}/libs/android.${arch}" done @@ -118,8 +121,13 @@ zip -9 -r "$AAR_PATH" META-INF prefab AndroidManifest.xml cd .. || exit rm -r "$DEST_PATH" -echo -echo "Congrats you have built an AAR containing libsodium! To use it with + +echo "Congrats you have built an AAR containing libsodium! +The build used a min Android SDK of version $SDK_VERSION +You can build for a different SDK version by specifying NDK_PLATFORM=\"android-{SDK_VERSION}\" +as an environment variable before running this script but the defaults should be fine. + +To use the aar with gradle or cmake (as set by default for Android Studio projects): - Edit the app/build.gradle file to add: diff --git a/dist-build/android-armv8-a.sh b/dist-build/android-armv8-a.sh index 5fa930c6..4da52447 100755 --- a/dist-build/android-armv8-a.sh +++ b/dist-build/android-armv8-a.sh @@ -2,4 +2,4 @@ export TARGET_ARCH=armv8-a+crypto export CFLAGS="-Os -march=${TARGET_ARCH}" export LDFLAGS="-Wl,-z,max-page-size=16384" -NDK_PLATFORM=android-21 ARCH=arm64 HOST_COMPILER=aarch64-linux-android "$(dirname "$0")/android-build.sh" +ARCH=arm64 HOST_COMPILER=aarch64-linux-android "$(dirname "$0")/android-build.sh" diff --git a/dist-build/android-build.sh b/dist-build/android-build.sh index 13c4638e..b1c300dc 100755 --- a/dist-build/android-build.sh +++ b/dist-build/android-build.sh @@ -1,9 +1,10 @@ #! /bin/sh if [ -z "$NDK_PLATFORM" ]; then - export NDK_PLATFORM="android-21" - echo "Compiling for default platform: [${NDK_PLATFORM}] - That can be changed by setting an NDK_PLATFORM environment variable." + echo "No NDK_PLATFORM specified, set to value such as \"android-{Min_SDK_VERSION}\" or just use android-aar.sh" + exit fi +SDK_VERSION=$( echo "$NDK_PLATFORM" | cut -f2 -d"-" ) export NDK_PLATFORM_COMPAT="${NDK_PLATFORM_COMPAT:-${NDK_PLATFORM}}" export NDK_API_VERSION="$(echo "$NDK_PLATFORM" | sed 's/^android-//')" export NDK_API_VERSION_COMPAT="$(echo "$NDK_PLATFORM_COMPAT" | sed 's/^android-//')" @@ -30,8 +31,8 @@ export TOOLCHAIN_DIR="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/${TOOLCHAIN_OS_ echo "$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/${TOOLCHAIN_OS_DIR}/${HOST_COMPILER}" export PATH="${PATH}:${TOOLCHAIN_DIR}/bin" -SDK_VERSION_NUM=$(echo $NDK_PLATFORM | cut -d'-' -f2) -export CC=${CC:-"${HOST_COMPILER}${SDK_VERSION_NUM}-clang"} + +export CC=${CC:-"${HOST_COMPILER}${SDK_VERSION}-clang"} echo echo "Warnings related to headers being present but not usable are due to functions" @@ -88,5 +89,5 @@ NPROCESSORS=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN PROCESSORS=${NPROCESSORS:-3} make clean && - make -j${PROCESSORS} install && + make -j"${PROCESSORS}" install && echo "libsodium has been installed into ${PREFIX}" diff --git a/dist-build/android-x86_64.sh b/dist-build/android-x86_64.sh index 25f44348..c5f74794 100755 --- a/dist-build/android-x86_64.sh +++ b/dist-build/android-x86_64.sh @@ -2,4 +2,4 @@ export TARGET_ARCH=westmere export CFLAGS="-Os -march=${TARGET_ARCH}" export LDFLAGS="-Wl,-z,max-page-size=16384" -NDK_PLATFORM=android-21 ARCH=x86_64 HOST_COMPILER=x86_64-linux-android "$(dirname "$0")/android-build.sh" +ARCH=x86_64 HOST_COMPILER=x86_64-linux-android "$(dirname "$0")/android-build.sh"