diff --git a/flutter/build_android_deps.sh b/flutter/build_android_deps.sh index 566196d52..ca6792916 100755 --- a/flutter/build_android_deps.sh +++ b/flutter/build_android_deps.sh @@ -4,7 +4,7 @@ # Required: # 1. set VCPKG_ROOT / ANDROID_NDK path environment variables # 2. vcpkg initialized -# 3. ndk >= 22 (if ndk< 22 you need to change LD as `export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld`) +# 3. ndk, version: 22 (if ndk < 22 you need to change LD as `export LD=$TOOLCHAIN/bin/$NDK_LLVM_TARGET-ld`) if [ -z "$ANDROID_NDK" ]; then echo "Failed! Please set ANDROID_NDK" @@ -16,66 +16,109 @@ if [ -z "$VCPKG_ROOT" ]; then exit 1 fi -PREFIX=$VCPKG_ROOT/installed/arm64-android/ +API_LEVEL="21" -echo "*** [Start] Build opus / libyuv from vcpkg" -export ANDROID_NDK_HOME=$ANDROID_NDK -pushd $VCPKG_ROOT -$VCPKG_ROOT/vcpkg install opus --triplet arm64-android -$VCPKG_ROOT/vcpkg install libyuv --triplet arm64-android -popd -echo "*** [Finished] Build opus / libyuv from vcpkg" +# NDK llvm toolchain +HOST_TAG="linux-x86_64" # current platform, set as `ls $ANDROID_NDK/toolchains/llvm/prebuilt/` +TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/$HOST_TAG + +function build { + ANDROID_ABI=$1 + VCPKG_TARGET=$2 + NDK_LLVM_TARGET=$3 + LIBVPX_TARGET=$4 + + PREFIX=$VCPKG_ROOT/installed/$VCPKG_TARGET/ + + # 1 + echo "*** [$ANDROID_ABI][Start] Build opus / libyuv from vcpkg" + export ANDROID_NDK_HOME=$ANDROID_NDK + pushd $VCPKG_ROOT + $VCPKG_ROOT/vcpkg install opus --triplet $VCPKG_TARGET + $VCPKG_ROOT/vcpkg install libyuv --triplet $VCPKG_TARGET + popd + echo "*** [$ANDROID_ABI][Finished] Build opus / libyuv from vcpkg" + + # 2 + echo "*** [$ANDROID_ABI][Start] Build libvpx" + pushd build/libvpx + export AR=$TOOLCHAIN/bin/${NDK_LLVM_TARGET}-ar + export AS=$TOOLCHAIN/bin/${NDK_LLVM_TARGET}-as + export LD=$TOOLCHAIN/bin/${NDK_LLVM_TARGET}-ld.gold # if ndk < 22, use aarch64-linux-android-ld + export RANLIB=$TOOLCHAIN/bin/${NDK_LLVM_TARGET}-ranlib + export STRIP=$TOOLCHAIN/bin/${NDK_LLVM_TARGET}-strip + + if [ $NDK_LLVM_TARGET == "arm-linux-androideabi" ] + then + export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi${API_LEVEL}-clang + export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi${API_LEVEL}-clang++ + else + export CC=$TOOLCHAIN/bin/${NDK_LLVM_TARGET}${API_LEVEL}-clang + export CXX=$TOOLCHAIN/bin/${NDK_LLVM_TARGET}${API_LEVEL}-clang++ + fi + + ./configure --target=$LIBVPX_TARGET \ + --enable-pic --disable-vp8 \ + --disable-webm-io \ + --disable-unit-tests \ + --disable-examples \ + --disable-libyuv \ + --disable-postproc \ + --disable-vp8 \ + --disable-tools \ + --disable-docs \ + --prefix=$PREFIX + make -j5 + make install + + popd + echo "*** [$ANDROID_ABI][Finished] Build libvpx" + + # 3 + echo "*** [$ANDROID_ABI][Start] Build oboe" + pushd build/oboe + cmake -DBUILD_SHARED_LIBS=true \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DANDROID_TOOLCHAIN=clang \ + -DANDROID_STL=c++_shared \ + -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ + -DCMAKE_INSTALL_PREFIX=$PREFIX \ + -DANDROID_ABI=$ANDROID_ABI \ + -DANDROID_PLATFORM=android-$API_LEVEL + make -j5 + make install + mv $PREFIX/lib/$ANDROID_ABI/liboboe.a $PREFIX/lib/ + popd + echo "*** [$ANDROID_ABI][Finished] Build oboe" + + echo "*** [$ANDROID_ABI][All Finished]" +} -echo "*** [Start] Build libvpx" git clone -b v1.11.0 --depth=1 https://github.com/webmproject/libvpx.git build/libvpx -pushd build/libvpx -export NDK=$ANDROID_NDK -export HOST_TAG=linux-x86_64 -export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG -export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar -export AS=$TOOLCHAIN/bin/aarch64-linux-android-as -export CC=$TOOLCHAIN/bin/aarch64-linux-android21-clang -export CXX=$TOOLCHAIN/bin/aarch64-linux-android21-clang++ -export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld.gold # if ndk < 22, use aarch64-linux-android-ld -export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib -export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip - -./configure --target=arm64-android-gcc \ - --enable-pic --disable-vp8 \ - --disable-webm-io \ - --disable-unit-tests \ - --disable-examples \ - --disable-libyuv \ - --disable-postproc \ - --disable-vp8 \ - --disable-tools \ - --disable-docs \ - --prefix=$PREFIX -make -j5 -make install - -popd -echo "*** [Finished] Build libvpx" - - -echo "*** [Start] Build oboe" git clone -b 1.6.1 --depth=1 https://github.com/google/oboe build/oboe -patch -d build/oboe -p1 < ../src/oboe.patch -pushd build/oboe -cmake -DBUILD_SHARED_LIBS=true \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DANDROID_TOOLCHAIN=clang \ - -DANDROID_STL=c++_shared \ - -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ - -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DANDROID_ABI=arm64-v8a \ - -DANDROID_PLATFORM=android-21 -make -j5 -make install -mv $PREFIX/lib/arm64-v8a/liboboe.a $PREFIX/lib/ -popd -echo "*** [Finished] Build oboe" -echo "*** [All Finished]" +patch -N -d build/oboe -p1 < ../src/oboe.patch + +# VCPKG_TARGET ANDROID_ABI +# arm64-android arm64-v8a +# arm-android armeabi-v7a +# x64-android x86_64 +# x86-android x86 + +# NDK_LLVM_TARGET +# aarch64-linux-android +# arm-linux-androideabi +# x86_64-linux-android +# i686-linux-android + +# LIBVPX_TARGET : +# arm64-android-gcc +# armv7-android-gcc +# x86_64-android-gcc +# x86-android-gcc + +# args: ANDROID_ABI VCPKG_TARGET NDK_LLVM_TARGET LIBVPX_TARGET +build arm64-v8a arm64-android aarch64-linux-android arm64-android-gcc +build armeabi-v7a arm-android arm-linux-androideabi armv7-android-gcc # rm -rf build/libvpx # rm -rf build/oboe \ No newline at end of file