-
Notifications
You must be signed in to change notification settings - Fork 479
feat: support android platform cross build #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
feihongxu0824
wants to merge
35
commits into
main
Choose a base branch
from
feat/platform_android
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+596
−38
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
6bdc954
init
feihongxu0824 dde9302
fix
feihongxu0824 7fad002
fix ruff ignore
feihongxu0824 902b6ef
add android ci
feihongxu0824 632a819
fix
feihongxu0824 a49cb00
fix
feihongxu0824 8146a6c
fix
feihongxu0824 d2fddc1
fix
feihongxu0824 9c6c0ca
add adb shell
feihongxu0824 157a2bc
add cache
feihongxu0824 6af5c63
fix
feihongxu0824 4a24d0e
add strip
feihongxu0824 258c701
fix
feihongxu0824 5708305
fix
feihongxu0824 cbeda2d
debug
feihongxu0824 d910056
fix
feihongxu0824 a6df4ce
fix
feihongxu0824 b0b0afa
fix
feihongxu0824 b6221ec
fix
feihongxu0824 c657d4c
fix
feihongxu0824 f711c07
fix
feihongxu0824 4df824d
fix
feihongxu0824 1f1c755
merge main
feihongxu0824 0a7a6b4
Merge branch 'main' into feat/platform_android
feihongxu0824 2a70a17
fix
feihongxu0824 d8a23b1
fix
feihongxu0824 519b088
fix rocksdb patch in ndk26
feihongxu0824 0ac61e2
fix
feihongxu0824 347c6e1
fix
feihongxu0824 d701631
fix
feihongxu0824 7934a01
fix
feihongxu0824 d20ec47
fix
feihongxu0824 7d86398
fix
feihongxu0824 08b4fa7
fix ignore
feihongxu0824 6a2feac
move script
feihongxu0824 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| name: android-cross-build | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
| paths-ignore: | ||
| - '**.md' | ||
| merge_group: | ||
| pull_request: | ||
| branches: [ "main" ] | ||
| paths-ignore: | ||
| - '**.md' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-android: | ||
| # sdkmanager and other Android tools are x86‑only; ARM runners fail with exit code 1 | ||
| # switch back to an x86 image so the setup-android action can install the SDK | ||
| runs-on: ubuntu-24.04 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| abi: [x86_64] | ||
| api: [21] | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Cache dependencies | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: | | ||
| ~/.ccache | ||
| key: ${{ runner.os }}-dependencies-cache-${{ hashFiles('**/CMakeLists.txt', 'thirdparty/**') }}-stl-fix | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y --no-install-recommends \ | ||
| cmake ninja-build git ca-certificates python3 \ | ||
| build-essential make ccache | ||
|
|
||
| - name: Setup Java 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '17' | ||
|
|
||
| - name: Setup Android SDK | ||
| uses: android-actions/setup-android@v3 | ||
|
|
||
| - name: Install NDK (side by side) | ||
| shell: bash | ||
| run: | | ||
| sdkmanager "ndk;26.1.10909125" | ||
|
|
||
| - name: Cache host protoc build | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: build-host | ||
| key: ${{ runner.os }}-host-protoc-${{ hashFiles('src/**', 'CMakeLists.txt') }}-stl-fix | ||
| restore-keys: | | ||
| ${{ runner.os }}-host-protoc- | ||
|
|
||
| - name: Use host env to compile protoc | ||
| shell: bash | ||
| run: | | ||
| git submodule update --init | ||
| if [ ! -d "build-host" ]; then | ||
| export CCACHE_BASEDIR="$GITHUB_WORKSPACE" | ||
| export CCACHE_NOHASHDIR=1 | ||
| export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_mtime,locale,time_macros | ||
|
|
||
| cmake -S . -B build-host -G Ninja \ | ||
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | ||
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| cmake --build build-host --target protoc --parallel | ||
| else | ||
| echo "Using cached host protoc build" | ||
| fi | ||
|
|
||
| - name: Cache Android build | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: build-android-${{ matrix.abi }} | ||
| key: ${{ runner.os }}-android-build-${{ matrix.abi }}-${{ hashFiles('src/**', 'CMakeLists.txt', 'cmake/**', 'thirdparty/**') }}-stl-fix-3 | ||
|
|
||
| - name: Configure and Build | ||
| shell: bash | ||
| run: | | ||
| git submodule foreach --recursive 'git stash --include-untracked' | ||
|
|
||
| export ANDROID_SDK_ROOT="$ANDROID_HOME" | ||
| export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/26.1.10909125" | ||
|
|
||
| export CCACHE_BASEDIR="$GITHUB_WORKSPACE" | ||
| export CCACHE_NOHASHDIR=1 | ||
| export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_mtime,locale,time_macros | ||
|
|
||
| if [ ! -d "build-android-${{ matrix.abi }}" ]; then | ||
| cmake -S . -B build-android-${{ matrix.abi }} -G Ninja \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ | ||
| -DANDROID_ABI=${{ matrix.abi }} \ | ||
| -DANDROID_PLATFORM=android-${{ matrix.api }} \ | ||
| -DANDROID_STL=c++_static \ | ||
| -DBUILD_PYTHON_BINDINGS=OFF \ | ||
| -DENABLE_NATIVE=OFF \ | ||
| -DAUTO_DETECT_ARCH=OFF \ | ||
| -DBUILD_TOOLS=OFF \ | ||
| -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build-host/bin/protoc" \ | ||
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | ||
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | ||
| -DCMAKE_VERBOSE_MAKEFILE=ON | ||
| cmake --build build-android-${{ matrix.abi }} --parallel --verbose | ||
| else | ||
| echo "Using cached Android build directory" | ||
| fi | ||
|
|
||
| - name: Cache examples build | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: examples/c++/build-android-examples-${{ matrix.abi }} | ||
| key: ${{ runner.os }}-examples-build-${{ matrix.abi }}-${{ hashFiles('examples/c++/**', 'CMakeLists.txt', 'src/**') }}-stl-fix-3 | ||
|
|
||
| - name: Build examples | ||
| shell: bash | ||
| run: | | ||
| export ANDROID_SDK_ROOT="$ANDROID_HOME" | ||
| export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/26.1.10909125" | ||
|
|
||
| if [ ! -d "examples/c++/build-android-examples-${{ matrix.abi }}" ]; then | ||
| cmake -S examples/c++ -B examples/c++/build-android-examples-${{ matrix.abi }} -G Ninja \ | ||
| -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ | ||
| -DANDROID_ABI=${{ matrix.abi }} \ | ||
| -DANDROID_PLATFORM=android-${{ matrix.api }} \ | ||
| -DANDROID_STL=c++_static \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \ | ||
| -DHOST_BUILD_DIR="build-android-${{ matrix.abi }}" \ | ||
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | ||
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| cmake --build examples/c++/build-android-examples-${{ matrix.abi }} --parallel | ||
| else | ||
| echo "Using cached examples build" | ||
| fi | ||
|
|
||
| - name: Run on Android emulator (arm64) and verify | ||
| uses: reactivecircus/android-emulator-runner@v2 | ||
| with: | ||
| api-level: ${{ matrix.api }} | ||
| arch: ${{ matrix.abi }} | ||
| # target: google_apis | ||
| # emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -netdelay none -netspeed full | ||
| # disable-animations: true | ||
| script: | | ||
| adb wait-for-device | ||
|
|
||
| echo "Device ABI:" | ||
| adb shell getprop ro.product.cpu.abi | ||
| adb shell getprop ro.product.cpu.abilist | ||
|
|
||
| echo "Checking binary sizes:" | ||
| ls -lah examples/c++/build-android-examples-${{ matrix.abi }}/ | ||
|
|
||
| # Push executables to device | ||
| adb push examples/c++/build-android-examples-${{ matrix.abi }}/ailego-example /data/local/tmp/ | ||
| adb push examples/c++/build-android-examples-${{ matrix.abi }}/core-example /data/local/tmp/ | ||
| adb push examples/c++/build-android-examples-${{ matrix.abi }}/db-example /data/local/tmp/ | ||
|
|
||
| adb shell chmod 755 /data/local/tmp/ailego-example | ||
| adb shell chmod 755 /data/local/tmp/core-example | ||
| adb shell chmod 755 /data/local/tmp/db-example | ||
|
|
||
| echo "File info on device:" | ||
| adb shell ls -la /data/local/tmp/ailego-example | ||
| adb shell ls -la /data/local/tmp/core-example | ||
| adb shell ls -la /data/local/tmp/db-example | ||
|
|
||
| echo "Running ailego example:" | ||
| adb shell 'cd /data/local/tmp && ./ailego-example' | ||
|
|
||
| echo "Running core example:" | ||
| adb shell 'cd /data/local/tmp && ./core-example' | ||
|
|
||
| echo "Running db example:" | ||
| adb shell 'cd /data/local/tmp && ./db-example' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,7 @@ exclude = [ | |
| ".git/", | ||
| ".venv/", | ||
| "venv/", | ||
| "thirdparty", | ||
| ] | ||
|
|
||
| [tool.ruff.lint] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/bin/bash | ||
| set -e | ||
| CURRENT_DIR=$(pwd) | ||
|
|
||
| ABI=${1:-"arm64-v8a"} | ||
| API_LEVEL=${2:-21} | ||
| BUILD_TYPE=${3:-"Release"} | ||
|
|
||
| # step1: use host env to compile protoc | ||
| echo "step1: building protoc for host..." | ||
| HOST_BUILD_DIR="build_host" | ||
| mkdir -p $HOST_BUILD_DIR | ||
| cd $HOST_BUILD_DIR | ||
|
|
||
| cmake -DCMAKE_BUILD_TYPE="$BUILD_TYPE" .. | ||
| make -j protoc | ||
| PROTOC_EXECUTABLE=$CURRENT_DIR/$HOST_BUILD_DIR/bin/protoc | ||
| cd $CURRENT_DIR | ||
|
|
||
| echo "step1: Done!!!" | ||
|
|
||
| # step2: cross build zvec based on android ndk | ||
| echo "step2: building zvec for android..." | ||
|
|
||
| # reset thirdparty directory | ||
| git submodule foreach --recursive 'git stash --include-untracked' | ||
|
|
||
| export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk | ||
| export ANDROID_HOME=$ANDROID_SDK_ROOT | ||
| export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/28.2.13676358 | ||
| export CMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake | ||
|
|
||
| export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin | ||
| export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools | ||
| export PATH=$PATH:$ANDROID_NDK_HOME | ||
|
|
||
| if [ -z "$ANDROID_NDK_HOME" ]; then | ||
| echo "error: ANDROID_NDK_HOME env not set" | ||
| echo "please install NDK and set env variable ANDROID_NDK_HOME" | ||
| exit 1 | ||
| fi | ||
|
|
||
| BUILD_DIR="build_android_${ABI}" | ||
| mkdir -p $BUILD_DIR | ||
| cd $BUILD_DIR | ||
|
|
||
| echo "configure CMake..." | ||
| cmake \ | ||
| -DANDROID_NDK="$ANDROID_NDK_HOME" \ | ||
| -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \ | ||
| -DANDROID_ABI="$ABI" \ | ||
| -DANDROID_NATIVE_API_LEVEL="$API_LEVEL" \ | ||
| -DANDROID_STL="c++_static" \ | ||
| -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ | ||
| -DBUILD_PYTHON_BINDINGS=OFF \ | ||
| -DBUILD_TOOLS=OFF \ | ||
| -DCMAKE_INSTALL_PREFIX="./install" \ | ||
| -DGLOBAL_CC_PROTOBUF_PROTOC=$PROTOC_EXECUTABLE \ | ||
| ../ | ||
|
|
||
| echo "building..." | ||
| CORE_COUNT=$(sysctl -n hw.ncpu) | ||
| make -j$CORE_COUNT | ||
|
|
||
| echo "step2: Done!!!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.