Skip to content

Commit

Permalink
Android build script
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Jun 6, 2024
1 parent e14491d commit 8055258
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
44 changes: 28 additions & 16 deletions build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

work_dir=$(pwd)

ANDROID_API_VERSION=21
# NDK homepage: https://developer.android.com/ndk/downloads#lts-downloads
ANDROID_NDK_VERSION=25.2.9519653
# Android commandline tools homepage: https://developer.android.com/studio/index.html#command-line-tools-only
CMDLINE_TOOLS_VERSION=6858069

export ANDROID_HOME=/tmp/Android/sdk
export NDK_HOME=${ANDROID_HOME}/ndk/25.2.9519653
export NDK_HOME=${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}
export PATH=$ANDROID_HOME/cmdline-tools/bin:$PATH
mkdir -p $ANDROID_HOME

Expand All @@ -17,13 +23,21 @@ function setup_env() {
cargo install cbindgen
apt update && apt install -y make llvm-dev libclang-dev clang pkg-config zip unzip curl default-jdk build-essential
cd /tmp/
curl -OL https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
curl -OL https://dl.google.com/android/repository/commandlinetools-linux-${CMDLINE_TOOLS_VERSION}_latest.zip
rm -rf /tmp/cmdline-tools
unzip commandlinetools-linux-6858069_latest.zip
unzip commandlinetools-linux-${CMDLINE_TOOLS_VERSION}_latest.zip
rm -rf $ANDROID_HOME/cmdline-tools
mv cmdline-tools $ANDROID_HOME
yes | sdkmanager --sdk_root=$ANDROID_HOME --licenses
sdkmanager --sdk_root=$ANDROID_HOME "ndk;25.2.9519653" "platforms;android-21"
if [ %? -ne 0 ]; then
echo "Failed to accept the licenses"
exit 1
fi
sdkmanager --sdk_root=$ANDROID_HOME "ndk;${ANDROID_NDK_VERSION}" "platforms;android-${ANDROID_API_VERSION}"
if [ %? -ne 0 ]; then
echo "Failed to install NDK"
exit 1
fi
}

function build_android() {
Expand All @@ -50,37 +64,35 @@ function build_android() {
local BASE=`dirname "$0"`
local HOST_OS=`uname -s | tr "[:upper:]" "[:lower:]"`
local HOST_ARCH=`uname -m | tr "[:upper:]" "[:lower:]"`

export PATH="$NDK_HOME/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH/bin/":$PATH

local android_tools="$NDK_HOME/toolchains/llvm/prebuilt/$HOST_OS-$HOST_ARCH/bin"
local api=21

export PATH="${android_tools}/":$PATH

for target in $targets; do
local target_dir=
case $target in
'armv7-linux-androideabi')
export CC_armv7_linux_androideabi="$android_tools/armv7a-linux-androideabi${api}-clang"
export CC_armv7_linux_androideabi="$android_tools/armv7a-linux-androideabi${ANDROID_API_VERSION}-clang"
export AR_armv7_linux_androideabi="$android_tools/llvm-ar"
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="$android_tools/armv7a-linux-androideabi${api}-clang"
export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="$android_tools/armv7a-linux-androideabi${ANDROID_API_VERSION}-clang"
target_dir=armeabi-v7a
;;
'x86_64-linux-android')
export CC_x86_64_linux_android="$android_tools/${target}${api}-clang"
export CC_x86_64_linux_android="$android_tools/${target}${ANDROID_API_VERSION}-clang"
export AR_x86_64_linux_android="$android_tools/llvm-ar"
export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="$android_tools/${target}${api}-clang"
export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="$android_tools/${target}${ANDROID_API_VERSION}-clang"
target_dir=x86_64
;;
'aarch64-linux-android')
export CC_aarch64_linux_android="$android_tools/${target}${api}-clang"
export CC_aarch64_linux_android="$android_tools/${target}${ANDROID_API_VERSION}-clang"
export AR_aarch64_linux_android="$android_tools/llvm-ar"
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$android_tools/${target}${api}-clang"
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$android_tools/${target}${ANDROID_API_VERSION}-clang"
target_dir=arm64-v8a
;;
'i686-linux-android')
export CC_i686_linux_android="$android_tools/${target}${api}-clang"
export CC_i686_linux_android="$android_tools/${target}${ANDROID_API_VERSION}-clang"
export AR_i686_linux_android="$android_tools/llvm-ar"
export CARGO_TARGET_I686_LINUX_ANDROID_LINKER="$android_tools/${target}${api}-clang"
export CARGO_TARGET_I686_LINUX_ANDROID_LINKER="$android_tools/${target}${ANDROID_API_VERSION}-clang"
target_dir=x86
;;
*)
Expand Down
1 change: 1 addition & 0 deletions cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = [

[export.rename]
"ArgVerbosity" = "OverTlsVerbosity"
"TrafficStatus" = "OverTlsTrafficStatus"

[enum]
prefix_with_name = true

0 comments on commit 8055258

Please sign in to comment.