329067e1c2
Ship the bundled nym-socks5-client on Windows and Android, not just Linux: - sidecar.rs resolves the binary per platform — nym-socks5-client.exe on Windows; on Android the sidecar rides in the APK jniLibs as libnym_socks5_client.so and is launched from the native-library dir (the one exec-allowed path), located via NATIVE_LIBS_DIR. - Restore a vendored, statically-linked OpenSSL. Upstream Grim got this from arti's static feature; dropping arti for Nym took it with it, which broke Android/cross builds (no system OpenSSL for the target) and left desktop dynamically linked to libssl. Inert on Windows/macOS (SChannel/Security.fw). - android.sh bundles the sidecar into jniLibs per ABI; scripts/nym-android.sh cross-builds it. Onboarding copy: Tor -> the Nym mixnet. Verified end to end on an x86_64 emulator: the sidecar extracts, launches, initialises, and opens the mixnet SOCKS5 proxy on 127.0.0.1:1080.
143 lines
4.3 KiB
Bash
Executable File
143 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
usage="Usage: android.sh [type] [platform|version] [flavor]\n - type: 'build' to run locally, 'lib' - .so for all platforms, 'release' - .apk for all platforms\n - platform, for 'build' type: 'v7', 'v8', 'x86'\n - version for 'lib' and 'release', example: '0.2.2'\n - optional flavor, for non-'lib' type: 'ci' for local maven, default - 'local' for external"
|
|
case $1 in
|
|
build|lib|release)
|
|
;;
|
|
*)
|
|
printf "$usage"
|
|
exit 1
|
|
esac
|
|
|
|
if [[ $1 == "build" ]]; then
|
|
case $2 in
|
|
v7|v8|x86)
|
|
;;
|
|
*)
|
|
printf "$usage"
|
|
exit 1
|
|
esac
|
|
fi
|
|
|
|
# Setup build directory
|
|
BASEDIR=$(cd "$(dirname "$0")" && pwd)
|
|
cd "${BASEDIR}" || exit 1
|
|
cd ..
|
|
|
|
# Install platforms and tools
|
|
rustup target add armv7-linux-androideabi
|
|
rustup target add aarch64-linux-android
|
|
rustup target add x86_64-linux-android
|
|
cargo install cargo-ndk
|
|
|
|
success=1
|
|
|
|
### Build native code
|
|
function build_lib() {
|
|
[[ $1 == "v7" ]] && arch=armeabi-v7a
|
|
[[ $1 == "v8" ]] && arch=arm64-v8a
|
|
[[ $1 == "x86" ]] && arch=x86_64
|
|
|
|
sed -i -e 's/"cdylib","rlib"]/"rlib"]/g' Cargo.toml
|
|
sed -i -e 's/"rlib"]/"cdylib","rlib"]/g' Cargo.toml
|
|
|
|
cargo ndk -t "${arch}" -o android/app/src/main/jniLibs build --profile release-apk
|
|
if [ $? -ne 0 ]; then
|
|
success=0
|
|
fi
|
|
|
|
sed -i -e 's/"cdylib","rlib"]/"rlib"]/g' Cargo.toml
|
|
rm -f Cargo.toml-e
|
|
|
|
# Bundle the Nym SOCKS5 sidecar beside libgrim.so. Named lib*.so so Android
|
|
# ships it in the APK's jniLibs and extracts it to the native-library dir —
|
|
# the only exec-allowed location for a child process (manifest needs
|
|
# extractNativeLibs=true). Built from the Nym workspace; see scripts/nym-android.sh.
|
|
[[ $1 == "v7" ]] && nym_target=armv7-linux-androideabi
|
|
[[ $1 == "v8" ]] && nym_target=aarch64-linux-android
|
|
[[ $1 == "x86" ]] && nym_target=x86_64-linux-android
|
|
nym_bin="${NYM_DIR:-../nym/target}/${nym_target}/release/nym-socks5-client"
|
|
if [ -f "${nym_bin}" ]; then
|
|
cp "${nym_bin}" "android/app/src/main/jniLibs/${arch}/libnym_socks5_client.so"
|
|
echo "bundled Nym sidecar: jniLibs/${arch}/libnym_socks5_client.so"
|
|
else
|
|
echo "WARN: Nym sidecar missing at ${nym_bin} — APK will have NO mixnet sidecar"
|
|
success=0
|
|
fi
|
|
}
|
|
|
|
### Build application
|
|
function build_apk() {
|
|
flavor=$3
|
|
[[ flavor == "" ]] && flavor="local"
|
|
cd android || exit 1
|
|
./gradlew clean
|
|
# Build signed apk if keystore exists
|
|
if [ ! -f keystore.properties ]; then
|
|
./gradlew assemble${flavor}Debug
|
|
if [ $? -ne 0 ]; then
|
|
success=0
|
|
fi
|
|
apk_path=app/build/outputs/apk/${flavor}/debug/app-${flavor}-debug.apk
|
|
else
|
|
./gradlew assemble${flavor}SignedRelease
|
|
if [ $? -ne 0 ]; then
|
|
success=0
|
|
fi
|
|
apk_path=app/build/outputs/apk/${flavor}/signedRelease/app-${flavor}-signedRelease.apk
|
|
fi
|
|
|
|
if [[ $1 == "" ]] && [ $success -eq 1 ]; then
|
|
# Launch application at all connected devices.
|
|
for SERIAL in $(adb devices | grep -v List | cut -f 1);
|
|
do
|
|
adb -s "$SERIAL" install ${apk_path}
|
|
sleep 1s
|
|
adb -s "$SERIAL" shell am start -n mw.gri.android/.MainActivity;
|
|
done
|
|
elif [ $success -eq 1 ]; then
|
|
# Get version
|
|
version=$2
|
|
if [[ -z "$version" ]]; then
|
|
version=v$(grep -m 1 -Po 'version = "\K[^"]*' ../Cargo.toml)
|
|
fi
|
|
# Setup release file name
|
|
name=grim-${version}-android-$1.apk
|
|
[[ $1 == "arm" ]] && name=grim-${version}-android.apk
|
|
rm -f "${name}"
|
|
mv ${apk_path} "${name}"
|
|
# Calculate checksum
|
|
checksum=grim-${version}-android-$1-sha256sum.txt
|
|
[[ $1 == "arm" ]] && checksum=grim-${version}-android-sha256sum.txt
|
|
rm -f "${checksum}"
|
|
sha256sum "${name}" > "${checksum}"
|
|
fi
|
|
|
|
cd ..
|
|
}
|
|
|
|
rm -rf android/app/src/main/jniLibs/*
|
|
if [[ $1 == "lib" ]]; then
|
|
build_lib "v7"
|
|
[ $success -eq 1 ] && build_lib "v8"
|
|
[ $success -eq 1 ] && build_lib "x86"
|
|
[ $success -eq 1 ] && exit 0
|
|
elif [[ $1 == "build" ]]; then
|
|
build_lib "$2"
|
|
[ $success -eq 1 ] && build_apk "" "" "$3"
|
|
[ $success -eq 1 ] && exit 0
|
|
else
|
|
rm -rf target/release-apk
|
|
rm -rf target/aarch64-linux-android
|
|
rm -rf target/x86_64-linux-android
|
|
rm -rf target/armv7-linux-androideabi
|
|
build_lib "v7"
|
|
[ $success -eq 1 ] && build_lib "v8"
|
|
[ $success -eq 1 ] && build_apk "arm" "$2" "$3"
|
|
rm -rf android/app/src/main/jniLibs/*
|
|
[ $success -eq 1 ] && build_lib "x86"
|
|
[ $success -eq 1 ] && build_apk "x86_64" "$2" "$3"
|
|
[ $success -eq 1 ] && exit 0
|
|
fi
|
|
|
|
exit 1 |