1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 04:38:53 +03:00
This commit is contained in:
Anton Afanasyeu
2026-06-08 12:38:57 +02:00
parent bfb41f06d9
commit c1591fa849
86 changed files with 5081 additions and 637 deletions

View File

@@ -1,8 +1,6 @@
#!/usr/bin/env bash
# Build libvpx for Android ABIs and produce libvpx.a for ANDROIDCAST_LIBVPX_LIB.
#
# With --enable-external-build, libvpx does not provide a libvpx.a make target;
# this script uses the NDK (ndk-build) + generated Android.mk, as upstream intends.
# Build libvpx, libopus, and libspeex for Android ABIs → build/native/<abi>/*.a
# CMake in ndk/ autolinks when those archives exist (ANDROIDCAST_HAVE_* = 1).
#
# Prerequisites:
# git submodule update --init third-party/libvpx
@@ -12,6 +10,7 @@
# ./scripts/build-native-codecs.sh arm64-v8a
# ANDROIDCAST_LIBVPX_LIB=$PWD/build/native/arm64-v8a/libvpx.a ./gradlew assembleDebug
#
# Produces (when sources present): libvpx.a, libopus.a, libspeex.a under build/native/<abi>/
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -226,6 +225,112 @@ if [[ "$OUT" != "$PROJECT_OUT" ]]; then
cp -f "$OUT/libvpx.a" "$PROJECT_OUT/libvpx.a"
fi
androidcast_ndk_api() { echo 29; }
androidcast_ndk_clang() {
local abi="$1"
local api
api="$(androidcast_ndk_api)"
case "$abi" in
arm64-v8a) echo "$NDK_HOST_BIN/aarch64-linux-android${api}-clang" ;;
armeabi-v7a) echo "$NDK_HOST_BIN/armv7a-linux-androideabi${api}-clang" ;;
x86_64) echo "$NDK_HOST_BIN/x86_64-linux-android${api}-clang" ;;
x86) echo "$NDK_HOST_BIN/i686-linux-android${api}-clang" ;;
*) echo "ERROR: unsupported ABI $abi" >&2; return 1 ;;
esac
}
androidcast_ndk_configure_host() {
case "$1" in
arm64-v8a) echo aarch64-linux-android ;;
armeabi-v7a) echo armv7a-linux-androideabi ;;
x86_64) echo x86_64-linux-android ;;
x86) echo i686-linux-android ;;
*) echo "$1" ;;
esac
}
build_opus_for_abi() {
local opus_src="$ROOT/third-party/opus"
if [[ ! -f "$opus_src/CMakeLists.txt" ]]; then
echo "Skip libopus: $opus_src missing (git submodule update --init third-party/opus)"
return 0
fi
local opus_build="$BUILD_DIR/opus-cmake"
rm -rf "$opus_build"
echo "Building libopus for $ABI (CMake) ..."
cmake -DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI="$ABI" \
-DANDROID_PLATFORM="android-$(androidcast_ndk_api)" \
-DBUILD_SHARED_LIBS=OFF \
-DOPUS_BUILD_SHARED_LIBRARY=OFF \
-DOPUS_BUILD_TESTING=OFF \
-DOPUS_BUILD_PROGRAMS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-B "$opus_build" -S "$opus_src"
cmake --build "$opus_build" --target opus -j"$(nproc)"
local opus_a="$opus_build/libopus.a"
if [[ ! -f "$opus_a" ]]; then
opus_a="$(find "$opus_build" -name 'libopus.a' | head -1)"
fi
if [[ ! -f "$opus_a" ]]; then
echo "ERROR: libopus.a not found after Opus build"
exit 1
fi
cp -f "$opus_a" "$PROJECT_OUT/libopus.a"
echo "Built: $PROJECT_OUT/libopus.a (size $(ls -lah "${PROJECT_OUT}/libopus.a" | awk '{print $5}'))"
}
build_speex_for_abi() {
local speex_src_real="$ROOT/third-party/speex"
if [[ ! -d "$speex_src_real" ]]; then
echo "Skip libspeex: $speex_src_real missing (git submodule update --init third-party/speex)"
return 0
fi
local speex_src="$speex_src_real"
local speex_build="$BUILD_DIR/speex-autotools"
if path_has_space "$speex_src_real"; then
speex_src="$STAGING/speex-src"
ln -sfn "$speex_src_real" "$speex_src"
fi
if [[ ! -f "$speex_src/configure" ]]; then
echo "Running speex autogen.sh ..."
(cd "$speex_src" && ./autogen.sh)
fi
rm -rf "$speex_build"
mkdir -p "$speex_build"
local cc host
cc="$(androidcast_ndk_clang "$ABI")"
host="$(androidcast_ndk_configure_host "$ABI")"
echo "Building libspeex for $ABI (autotools) ..."
(
cd "$speex_build"
"$speex_src/configure" \
--host="$host" \
--prefix="$speex_build/install" \
--disable-shared \
--enable-static \
--disable-binaries \
--with-pic \
CC="$cc" \
CFLAGS="-fPIC -O2"
make -j"$(nproc)"
)
local speex_a="$speex_build/libspeex/.libs/libspeex.a"
if [[ ! -f "$speex_a" ]]; then
speex_a="$(find "$speex_build" -name 'libspeex.a' | head -1)"
fi
if [[ ! -f "$speex_a" ]]; then
echo "ERROR: libspeex.a not found after Speex build"
exit 1
fi
cp -f "$speex_a" "$PROJECT_OUT/libspeex.a"
echo "Built: $PROJECT_OUT/libspeex.a (size $(ls -lah "${PROJECT_OUT}/libspeex.a" | awk '{print $5}'))"
}
build_opus_for_abi
build_speex_for_abi
echo ""
echo "Built: $PROJECT_OUT/libvpx.a (size $(ls -lah "${PROJECT_OUT}/libvpx.a" | awk '{print $5}'))"
if [[ -n "$STAGING" ]]; then
@@ -233,5 +338,5 @@ if [[ -n "$STAGING" ]]; then
fi
echo "Build other ABIs as needed, e.g.:"
echo " ./scripts/build-native-codecs.sh armeabi-v7a"
echo "Then rebuild the APK (CMake picks build/native/<abi>/libvpx.a per ABI):"
echo "Then rebuild the APK (CMake autolinks build/native/<abi>/*.a per ABI):"
echo " ./gradlew assembleDebug"