refactor: enhance Android build scripts with dynamic example discovery and configurable ABI, and correct LLM SDK path.

This commit is contained in:
dian.yuan 2026-02-25 13:43:07 +08:00
parent 194e4b6b18
commit 72e0647351
4 changed files with 92 additions and 31 deletions

View file

@ -1,11 +1,75 @@
#!/bin/bash
if [ ! -d "$NDK_PATH" ]; then
echo "Error: NDK_PATH '$NDK_PATH' not found."
echo "Please set NDK_PATH environment variable to your Android NDK directory."
set -e
#
# Copyright (C) 2024-2025 Amlogic, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
usage() {
echo "Usage: $0 [-a <target_abi>]"
echo " -a <target_abi> : Target ABI (default: arm64-v8a)"
echo " -h : Show this help message"
exit 1
}
# Default values
TARGET_ABI=arm64-v8a
# Parse arguments
while getopts 'a:h' opt; do
case "$opt" in
a)
TARGET_ABI=$OPTARG
;;
h)
usage
;;
*)
usage
;;
esac
done
if [ -z "${ANDROID_NDK_PATH}" ]; then
if [ -n "${ANDROID_NDK}" ]; then
ANDROID_NDK_PATH=${ANDROID_NDK}
elif [ -n "${ANDROID_NDK_HOME}" ]; then
ANDROID_NDK_PATH=${ANDROID_NDK_HOME}
else
echo "Error: ANDROID_NDK_PATH is not set."
echo "Please set ANDROID_NDK_PATH to your Android NDK directory."
exit 1
fi
fi
$NDK_PATH/ndk-build \
NDK_PROJECT_PATH=. \
APP_BUILD_SCRIPT=./Android.mk \
NDK_APPLICATION_MK=./Application.mk
ROOT_PWD=$(cd "$(dirname $0)" && pwd)
BUILD_DIR=${ROOT_PWD}/build/android
echo "Building LLMs for Android (ndk-build)..."
echo "NDK_PATH: ${ANDROID_NDK_PATH}"
echo "TARGET_ABI: ${TARGET_ABI}"
echo "BUILD_DIR: ${BUILD_DIR}"
mkdir -p ${BUILD_DIR}
${ANDROID_NDK_PATH}/ndk-build \
NDK_PROJECT_PATH="${ROOT_PWD}" \
APP_BUILD_SCRIPT="${ROOT_PWD}/Android.mk" \
NDK_APPLICATION_MK="${ROOT_PWD}/Application.mk" \
NDK_OUT="${BUILD_DIR}/obj" \
NDK_LIBS_OUT="${BUILD_DIR}/libs" \
APP_ABI="${TARGET_ABI}"
echo "Build complete. Libs in ${BUILD_DIR}/libs"