-
Notifications
You must be signed in to change notification settings - Fork 114
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
22
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.
Open
Changes from all commits
Commits
Show all changes
22 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 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,195 @@ | ||
| 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: | ||
| runs-on: ubuntu-22.04 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| # abi: [arm64-v8a, armeabi-v7a, x86_64] | ||
| 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 | ||
| restore-keys: | | ||
| ${{ runner.os }}-dependencies-cache- | ||
|
|
||
| - 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 NDK | ||
| uses: android-actions/setup-android@v3 | ||
|
|
||
| - name: Install NDK (side by side) | ||
| shell: bash | ||
| run: | | ||
| # yes | sdkmanager --licenses | ||
| 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 | ||
| # Setup ccache for host build | ||
| 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-2 | ||
|
|
||
| - 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" | ||
|
|
||
| # Setup ccache | ||
| 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 \ | ||
| -DBUILD_TOOLS=OFF \ | ||
| -DGLOBAL_CC_PROTOBUF_PROTOC="$GITHUB_WORKSPACE/build-host/bin/protoc" \ | ||
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | ||
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | ||
| cmake --build build-android-${{ matrix.abi }} --parallel | ||
| 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-2 | ||
|
|
||
| - name: Build examples | ||
| shell: bash | ||
| run: | | ||
| 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: Install ADB and setup Android emulator | ||
| 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 | ||
| # disable-animations: true | ||
| script: | | ||
| # Wait for device to be ready | ||
| adb wait-for-device | ||
|
|
||
| # Check file sizes before pushing | ||
| echo "Checking binary sizes:" | ||
| ls -lah examples/c++/build-android-examples-${{ matrix.abi }}/ | ||
|
|
||
| # Check device architecture | ||
| echo "Device architecture info:" | ||
| adb shell 'getprop ro.product.cpu.abi' | ||
| adb shell 'getprop ro.product.cpu.abilist' | ||
|
|
||
| # 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/ | ||
|
|
||
| # Make executables executable | ||
| 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' | ||
|
|
||
| # Verify file integrity | ||
| 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 "Exit code: $?" | ||
|
|
||
| echo "Running core example:" | ||
| adb shell 'cd /data/local/tmp && ./core-example' | ||
| echo "Exit code: $?" | ||
|
|
||
| echo "Running db example:" | ||
| adb shell 'cd /data/local/tmp && ./db-example' | ||
| echo "Exit code: $?" | ||
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 |
|---|---|---|
| @@ -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
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.
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.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 4 days ago
In general, fix this by explicitly specifying
permissionsfor theGITHUB_TOKENin the workflow, either at the top level (applies to all jobs) or per-job, and restricting them to the minimum needed. For this build-focused workflow, all steps only need to read repository contents (the checkout action and cache keys based onhashFiles), socontents: readis sufficient.The best minimal fix without changing functionality is to add a top-level
permissionsblock right after thename:declaration (or beforejobs:) in.github/workflows/android_build.yml. This will apply to thebuild-androidjob and any future jobs that do not override permissions. No additional imports or methods are needed; this is purely a YAML configuration change. Concretely, insert:near the top of the file, keeping indentation consistent with other top-level keys.