From 42b547d3112513788b5ce2e7b57e0854908538e3 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Mon, 29 Aug 2022 18:51:25 +0200 Subject: [PATCH] fix: repair the Android build (#905) Rather than hardcoding the NDK version inside a script, encode it as a file in the filesystem, which is easier to share. Make sure we use the desired NDK by setting environment variables. Use `-androidabi 21`, which: 1. is what rclone did: https://github.com/rclone/rclone/commit/8390ba4ca9f18fea546ecdfdf8f86aed5c36030f 2. is the minimum ABI used by probe-android: https://github.com/ooni/probe-android/blob/994651be52ff75ee3a00dba499ec7c7b40ab25c1/app/build.gradle#L10 Part of https://github.com/ooni/probe/issues/2130 --- .github/workflows/android.yml | 1 + MOBILE/android/ensure | 2 +- MOBILE/gomobile | 16 +++++++++++++++- NDKVERSION | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 NDKVERSION diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 2b9fa7a..08a6724 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -5,6 +5,7 @@ on: branches: - "release/**" - "fullbuild" + - "androidbuild" tags: - "v*" diff --git a/MOBILE/android/ensure b/MOBILE/android/ensure index 0818fa9..f8f3edb 100755 --- a/MOBILE/android/ensure +++ b/MOBILE/android/ensure @@ -4,7 +4,7 @@ set -euo pipefail __install_extra="build-tools;32.0.0 platforms;android-31" -__ndk_version="23.1.7779620" +__ndk_version=$(cat ./NDKVERSION) ANDROID_HOME=$(./MOBILE/android/home) diff --git a/MOBILE/gomobile b/MOBILE/gomobile index 6f29573..8140de6 100755 --- a/MOBILE/gomobile +++ b/MOBILE/gomobile @@ -42,6 +42,14 @@ else OONI_PSIPHON_TAGS="" fi +MAYBE_ANDROID_API="" +if [[ $TARGET == "android" ]]; then + ANDROID_HOME=$(./MOBILE/android/home) + NDK_VERSION=$(cat NDKVERSION) + ANDROID_NDK_HOME=$ANDROID_HOME/ndk/$NDK_VERSION + MAYBE_ANDROID_API="-androidapi 21" +fi + PRODUCT=$(basename $PACKAGE) function cleanup() { @@ -51,11 +59,17 @@ function cleanup() { trap cleanup EXIT set -x + +# for documenting the environ variables used by the build +export ANDROID_HOME=$ANDROID_HOME +export ANDROID_NDK_HOME=$ANDROID_NDK_HOME + go install golang.org/x/mobile/cmd/gomobile@latest $(go env GOPATH)/bin/gomobile init # Adding gomobile to go.mod as documented by golang.org/wiki/Mobile go get -d golang.org/x/mobile/cmd/gomobile $(go env GOPATH)/bin/gomobile bind -target $TARGET \ - -o ./MOBILE/$TARGET/$PRODUCT.$EXT -tags="$OONI_PSIPHON_TAGS" \ + -o ./MOBILE/$TARGET/$PRODUCT.$EXT $MAYBE_ANDROID_API \ + -tags="$OONI_PSIPHON_TAGS" \ -ldflags '-s -w' ${GOLANG_EXTRA_FLAGS:-} $PACKAGE diff --git a/NDKVERSION b/NDKVERSION new file mode 100644 index 0000000..6094064 --- /dev/null +++ b/NDKVERSION @@ -0,0 +1 @@ +25.1.8937393