From 3178426f9b5ad0f7bfc31a7efe8299675f738364 Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 13:35:32 +0900 Subject: [PATCH 1/8] android so file --- .github/workflows/create_release.yaml | 52 ++++++++++++++++ README.md | 1 + scripts/build_libedax_android.sh | 90 +++++++++++++++++++++++++++ scripts/test_android_build.sh | 53 ++++++++++++++++ 4 files changed, 196 insertions(+) create mode 100755 scripts/build_libedax_android.sh create mode 100755 scripts/test_android_build.sh diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index e238c7f46ab..7fb3bcf767f 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -68,3 +68,55 @@ jobs: tag_name: ${{ env.CURRENT_VERSION }} files: ${{ env.PUBLISH_DIR }}/${{ runner.os }}.zip generate_release_notes: true + + create_android_release: + # See: .github/workflows/create_release_pr.yaml + if: ${{ github.head_ref == 'prepare_for_release' && github.event.pull_request.merged == true }} + env: + OUTPUT_DIR: libedax_output + PUBLISH_DIR: dst + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + android_abi: [arm64-v8a, armeabi-v7a, x86_64, x86] + + steps: + - uses: actions/checkout@v5 + + - uses: dart-lang/setup-dart@v1 + + - name: inject current version + shell: bash + run: echo "CURRENT_VERSION=$(dart pub deps --style compact | grep "libedax4dart" | cut -c 14-)" >> $GITHUB_ENV + + - name: Setup Android NDK + uses: nttld/setup-ndk@v1 + with: + ndk-version: r25c + add-to-path: true + + - name: Install p7zip + run: sudo apt-get update && sudo apt-get install -y p7zip-full + + - name: Build Android libedax + shell: bash + env: + android_abi: ${{ matrix.android_abi }} + dst: ${{ env.OUTPUT_DIR }} + run: ./scripts/build_libedax_android.sh + + - name: compress Android files + shell: bash + run: | + mkdir -p ${{ env.PUBLISH_DIR }} + cd ${{ env.OUTPUT_DIR }}/android/${{ matrix.android_abi }} + zip -r ../../../${{ env.PUBLISH_DIR }}/Android-${{ matrix.android_abi }}.zip . + + - uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + with: + tag_name: ${{ env.CURRENT_VERSION }} + files: ${{ env.PUBLISH_DIR }}/Android-${{ matrix.android_abi }}.zip + generate_release_notes: true diff --git a/README.md b/README.md index 0ab36dd099f..ec65425a768 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ With using libedax4dart, you can execute functions equivalent to [edax](https:// - macos: `libedax.universal.dylib` - windows: `libedax-x64.dll` - linux: `libedax.so` + - android: `libedax-{arch}.so` (where {arch} is arm64-v8a, armeabi-v7a, x86_64, or x86) - (Optional) data for edax - `book.dat` - `eval.dat` diff --git a/scripts/build_libedax_android.sh b/scripts/build_libedax_android.sh new file mode 100755 index 00000000000..1abe8de2bd4 --- /dev/null +++ b/scripts/build_libedax_android.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# shellcheck disable=SC2154 +set -euxo pipefail + +# NOTE: require some environment variables. +# android_abi: Android ABI (arm64-v8a, armeabi-v7a, x86_64, x86) +# dst: output directory (e.g. build) +# +# example: +# android_abi="arm64-v8a" dst="." ./scripts/build_libedax_android.sh + +if [ -z "${android_abi:-}" ]; then + echo "Error: android_abi environment variable is required" + exit 1 +fi + +# Clone and setup edax-reversi +rm -rf edax-reversi +git clone https://github.com/sensuikan1973/edax-reversi +cd edax-reversi +git remote update --prune +git switch libedax_sensuikan1973 +git checkout "$(cat ../.libedax-version)" + +# Download eval data +mkdir -p data +curl -OL https://github.com/abulmo/edax-reversi/releases/download/v4.4/eval.7z +7za x eval.7z -y + +# Set up Android NDK toolchain +export ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME + +# Detect the correct prebuilt directory based on the host OS +if [[ "$OSTYPE" == "darwin"* ]]; then + export NDK_TOOLCHAIN=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64 +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + export NDK_TOOLCHAIN=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64 +else + echo "Error: Unsupported OS type: $OSTYPE" + exit 1 +fi + +# Set up compiler and flags based on architecture +case "$android_abi" in + "arm64-v8a") + export CC=$NDK_TOOLCHAIN/bin/aarch64-linux-android21-clang + export ARCH_FLAGS="-march=armv8-a" + export OUTPUT_NAME="libedax-arm64-v8a.so" + ;; + "armeabi-v7a") + export CC=$NDK_TOOLCHAIN/bin/armv7a-linux-androideabi21-clang + export ARCH_FLAGS="-march=armv7-a -mfpu=neon" + export OUTPUT_NAME="libedax-armeabi-v7a.so" + ;; + "x86_64") + export CC=$NDK_TOOLCHAIN/bin/x86_64-linux-android21-clang + export ARCH_FLAGS="-m64" + export OUTPUT_NAME="libedax-x86_64.so" + ;; + "x86") + export CC=$NDK_TOOLCHAIN/bin/i686-linux-android21-clang + export ARCH_FLAGS="-m32" + export OUTPUT_NAME="libedax-x86.so" + ;; + *) + echo "Error: Unsupported android_abi: $android_abi" + exit 1 + ;; +esac + +# Build libedax for Android +mkdir -p bin +cd src + +# Custom build command for Android SO file +$CC -std=c99 -O3 -DNDEBUG -DLIB_BUILD -DANDROID -fPIC -shared $ARCH_FLAGS \ + all.c -o ../bin/$OUTPUT_NAME -lm -llog + +cd ../../ + +# Setup output directory structure +mkdir -p "${dst:-.}/android/$android_abi/bin" +mkdir -p "${dst:-.}/android/$android_abi/data" + +# Copy built library and data +cp "edax-reversi/bin/$OUTPUT_NAME" "${dst:-.}/android/$android_abi/bin/" +cp -r edax-reversi/data/* "${dst:-.}/android/$android_abi/data/" + +echo "Android libedax build completed for $android_abi" +echo "Output: ${dst:-.}/android/$android_abi/bin/$OUTPUT_NAME" diff --git a/scripts/test_android_build.sh b/scripts/test_android_build.sh new file mode 100755 index 00000000000..7b03f953fbc --- /dev/null +++ b/scripts/test_android_build.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Test script for Android build (requires Android NDK to be installed locally) +set -euo pipefail + +echo "Testing Android libedax build script..." + +# Check if Android NDK is available +if [ -z "${ANDROID_NDK_ROOT:-}" ] && [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then + echo "ANDROID_NDK_ROOT or ANDROID_NDK_LATEST_HOME not set. Attempting to auto-detect..." + + # Try to find Android NDK in common locations + POSSIBLE_NDK_PATHS=( + "$HOME/Library/Android/sdk/ndk" + "$HOME/Android/Sdk/ndk" + "/usr/local/android-ndk" + "/opt/android-ndk" + ) + + for ndk_base in "${POSSIBLE_NDK_PATHS[@]}"; do + if [ -d "$ndk_base" ]; then + # Find the latest version + latest_ndk=$(find "$ndk_base" -maxdepth 1 -type d -name "*.*.*" | sort -V | tail -1) + if [ -n "$latest_ndk" ] && [ -d "$latest_ndk" ]; then + export ANDROID_NDK_LATEST_HOME="$latest_ndk" + echo "Found Android NDK at: $ANDROID_NDK_LATEST_HOME" + break + fi + fi + done + + if [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then + echo "Error: Android NDK not found in common locations." + echo "Please install Android NDK via Android Studio SDK Manager or download from:" + echo "https://developer.android.com/ndk/downloads" + echo "" + echo "Or set the environment variable manually:" + echo "export ANDROID_NDK_LATEST_HOME=/path/to/your/ndk" + exit 1 + fi +fi + +# Set ANDROID_NDK_LATEST_HOME if not set but ANDROID_NDK_ROOT is set +if [ -z "${ANDROID_NDK_LATEST_HOME:-}" ] && [ -n "${ANDROID_NDK_ROOT:-}" ]; then + export ANDROID_NDK_LATEST_HOME="$ANDROID_NDK_ROOT" +fi + +# Test building for arm64-v8a +echo "Building for arm64-v8a..." +android_abi="arm64-v8a" dst="test_output" ./scripts/build_libedax_android.sh + +echo "Build successful! Check test_output/android/arm64-v8a/ for the generated files." +echo "Generated files:" +find test_output/android/arm64-v8a/ -name "*.so" -o -name "*.dat" | head -10 From 321eaee7fdbcbad157ed558cfcdfd4dee5f13c4e Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 14:08:05 +0900 Subject: [PATCH 2/8] SC2086 --- scripts/build_libedax_android.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build_libedax_android.sh b/scripts/build_libedax_android.sh index 1abe8de2bd4..c246da45993 100755 --- a/scripts/build_libedax_android.sh +++ b/scripts/build_libedax_android.sh @@ -73,8 +73,8 @@ mkdir -p bin cd src # Custom build command for Android SO file -$CC -std=c99 -O3 -DNDEBUG -DLIB_BUILD -DANDROID -fPIC -shared $ARCH_FLAGS \ - all.c -o ../bin/$OUTPUT_NAME -lm -llog +$CC -std=c99 -O3 -DNDEBUG -DLIB_BUILD -DANDROID -fPIC -shared "$ARCH_FLAGS" \ + all.c -o "../bin/$OUTPUT_NAME" -lm -llog cd ../../ From db49d9531605c655e9ede5669c44df8861b95d07 Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 14:09:14 +0900 Subject: [PATCH 3/8] fix --- .github/workflows/create_release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index 7fb3bcf767f..f7c68214f67 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -71,7 +71,7 @@ jobs: create_android_release: # See: .github/workflows/create_release_pr.yaml - if: ${{ github.head_ref == 'prepare_for_release' && github.event.pull_request.merged == true }} + # if: ${{ github.head_ref == 'prepare_for_release' && github.event.pull_request.merged == true }} env: OUTPUT_DIR: libedax_output PUBLISH_DIR: dst From c8acf3a8d0e029ee85d461ac11a8925b617d2c53 Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 14:13:19 +0900 Subject: [PATCH 4/8] fix --- scripts/build_libedax_android.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build_libedax_android.sh b/scripts/build_libedax_android.sh index c246da45993..b2d7e08bf87 100755 --- a/scripts/build_libedax_android.sh +++ b/scripts/build_libedax_android.sh @@ -1,5 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2154 +# shellcheck disable=SC2154,SC2086 set -euxo pipefail # NOTE: require some environment variables. @@ -73,8 +73,8 @@ mkdir -p bin cd src # Custom build command for Android SO file -$CC -std=c99 -O3 -DNDEBUG -DLIB_BUILD -DANDROID -fPIC -shared "$ARCH_FLAGS" \ - all.c -o "../bin/$OUTPUT_NAME" -lm -llog +$CC -std=c99 -O3 -DNDEBUG -DLIB_BUILD -DANDROID -fPIC -shared $ARCH_FLAGS \ + all.c -o ../bin/$OUTPUT_NAME -lm -llog cd ../../ From 4afdf3c19353f258414aac8224129931293336bc Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 14:16:04 +0900 Subject: [PATCH 5/8] test build --- scripts/test_android_armv7_build.sh | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 scripts/test_android_armv7_build.sh diff --git a/scripts/test_android_armv7_build.sh b/scripts/test_android_armv7_build.sh new file mode 100644 index 00000000000..edbe807586e --- /dev/null +++ b/scripts/test_android_armv7_build.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Test script for armeabi-v7a build specifically +set -euo pipefail + +echo "Testing Android libedax build for armeabi-v7a..." + +# Check if Android NDK is available +if [ -z "${ANDROID_NDK_ROOT:-}" ] && [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then + echo "ANDROID_NDK_ROOT or ANDROID_NDK_LATEST_HOME not set. Attempting to auto-detect..." + + # Try to find Android NDK in common locations + POSSIBLE_NDK_PATHS=( + "$HOME/Library/Android/sdk/ndk" + "$HOME/Android/Sdk/ndk" + "/usr/local/android-ndk" + "/opt/android-ndk" + ) + + for ndk_base in "${POSSIBLE_NDK_PATHS[@]}"; do + if [ -d "$ndk_base" ]; then + # Find the latest version + latest_ndk=$(find "$ndk_base" -maxdepth 1 -type d -name "*.*.*" | sort -V | tail -1) + if [ -n "$latest_ndk" ] && [ -d "$latest_ndk" ]; then + export ANDROID_NDK_LATEST_HOME="$latest_ndk" + echo "Found Android NDK at: $ANDROID_NDK_LATEST_HOME" + break + fi + fi + done + + if [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then + echo "Error: Android NDK not found in common locations." + exit 1 + fi +fi + +# Test building for armeabi-v7a specifically +echo "Building for armeabi-v7a..." +android_abi="armeabi-v7a" dst="test_output_armv7" ./scripts/build_libedax_android.sh + +echo "Build successful! Check test_output_armv7/android/armeabi-v7a/ for the generated files." +echo "Generated files:" +find test_output_armv7/android/armeabi-v7a/ -name "*.so" -o -name "*.dat" | head -10 From ba4954808f230d95b91f4f697cd8acac0ae0d1bd Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 14:16:22 +0900 Subject: [PATCH 6/8] Revert "test build" This reverts commit 4afdf3c19353f258414aac8224129931293336bc. --- scripts/test_android_armv7_build.sh | 43 ----------------------------- 1 file changed, 43 deletions(-) delete mode 100644 scripts/test_android_armv7_build.sh diff --git a/scripts/test_android_armv7_build.sh b/scripts/test_android_armv7_build.sh deleted file mode 100644 index edbe807586e..00000000000 --- a/scripts/test_android_armv7_build.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# Test script for armeabi-v7a build specifically -set -euo pipefail - -echo "Testing Android libedax build for armeabi-v7a..." - -# Check if Android NDK is available -if [ -z "${ANDROID_NDK_ROOT:-}" ] && [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then - echo "ANDROID_NDK_ROOT or ANDROID_NDK_LATEST_HOME not set. Attempting to auto-detect..." - - # Try to find Android NDK in common locations - POSSIBLE_NDK_PATHS=( - "$HOME/Library/Android/sdk/ndk" - "$HOME/Android/Sdk/ndk" - "/usr/local/android-ndk" - "/opt/android-ndk" - ) - - for ndk_base in "${POSSIBLE_NDK_PATHS[@]}"; do - if [ -d "$ndk_base" ]; then - # Find the latest version - latest_ndk=$(find "$ndk_base" -maxdepth 1 -type d -name "*.*.*" | sort -V | tail -1) - if [ -n "$latest_ndk" ] && [ -d "$latest_ndk" ]; then - export ANDROID_NDK_LATEST_HOME="$latest_ndk" - echo "Found Android NDK at: $ANDROID_NDK_LATEST_HOME" - break - fi - fi - done - - if [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then - echo "Error: Android NDK not found in common locations." - exit 1 - fi -fi - -# Test building for armeabi-v7a specifically -echo "Building for armeabi-v7a..." -android_abi="armeabi-v7a" dst="test_output_armv7" ./scripts/build_libedax_android.sh - -echo "Build successful! Check test_output_armv7/android/armeabi-v7a/ for the generated files." -echo "Generated files:" -find test_output_armv7/android/armeabi-v7a/ -name "*.so" -o -name "*.dat" | head -10 From 4d838a63057bf00c53fb0ecf2ac163e13cecade4 Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 14:17:30 +0900 Subject: [PATCH 7/8] fix --- scripts/test_android_build.sh | 53 ----------------------------------- 1 file changed, 53 deletions(-) delete mode 100755 scripts/test_android_build.sh diff --git a/scripts/test_android_build.sh b/scripts/test_android_build.sh deleted file mode 100755 index 7b03f953fbc..00000000000 --- a/scripts/test_android_build.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -# Test script for Android build (requires Android NDK to be installed locally) -set -euo pipefail - -echo "Testing Android libedax build script..." - -# Check if Android NDK is available -if [ -z "${ANDROID_NDK_ROOT:-}" ] && [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then - echo "ANDROID_NDK_ROOT or ANDROID_NDK_LATEST_HOME not set. Attempting to auto-detect..." - - # Try to find Android NDK in common locations - POSSIBLE_NDK_PATHS=( - "$HOME/Library/Android/sdk/ndk" - "$HOME/Android/Sdk/ndk" - "/usr/local/android-ndk" - "/opt/android-ndk" - ) - - for ndk_base in "${POSSIBLE_NDK_PATHS[@]}"; do - if [ -d "$ndk_base" ]; then - # Find the latest version - latest_ndk=$(find "$ndk_base" -maxdepth 1 -type d -name "*.*.*" | sort -V | tail -1) - if [ -n "$latest_ndk" ] && [ -d "$latest_ndk" ]; then - export ANDROID_NDK_LATEST_HOME="$latest_ndk" - echo "Found Android NDK at: $ANDROID_NDK_LATEST_HOME" - break - fi - fi - done - - if [ -z "${ANDROID_NDK_LATEST_HOME:-}" ]; then - echo "Error: Android NDK not found in common locations." - echo "Please install Android NDK via Android Studio SDK Manager or download from:" - echo "https://developer.android.com/ndk/downloads" - echo "" - echo "Or set the environment variable manually:" - echo "export ANDROID_NDK_LATEST_HOME=/path/to/your/ndk" - exit 1 - fi -fi - -# Set ANDROID_NDK_LATEST_HOME if not set but ANDROID_NDK_ROOT is set -if [ -z "${ANDROID_NDK_LATEST_HOME:-}" ] && [ -n "${ANDROID_NDK_ROOT:-}" ]; then - export ANDROID_NDK_LATEST_HOME="$ANDROID_NDK_ROOT" -fi - -# Test building for arm64-v8a -echo "Building for arm64-v8a..." -android_abi="arm64-v8a" dst="test_output" ./scripts/build_libedax_android.sh - -echo "Build successful! Check test_output/android/arm64-v8a/ for the generated files." -echo "Generated files:" -find test_output/android/arm64-v8a/ -name "*.so" -o -name "*.dat" | head -10 From 248b2b2c12c856a3a97c18f10ee6cc6460c240b0 Mon Sep 17 00:00:00 2001 From: sensuikan1973 Date: Mon, 3 Nov 2025 14:17:47 +0900 Subject: [PATCH 8/8] upd --- .github/workflows/create_release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index f7c68214f67..7fb3bcf767f 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -71,7 +71,7 @@ jobs: create_android_release: # See: .github/workflows/create_release_pr.yaml - # if: ${{ github.head_ref == 'prepare_for_release' && github.event.pull_request.merged == true }} + if: ${{ github.head_ref == 'prepare_for_release' && github.event.pull_request.merged == true }} env: OUTPUT_DIR: libedax_output PUBLISH_DIR: dst