build-android-x86-64.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. set -ex
  3. # see https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-android
  4. dir=build-android-x86-64
  5. mkdir -p $dir
  6. cd $dir
  7. # Note from https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-android
  8. # (optional) remove the hardcoded debug flag in Android NDK android-ndk
  9. # issue: https://github.com/android/ndk/issues/243
  10. #
  11. # open $ANDROID_NDK/build/cmake/android.toolchain.cmake for ndk < r23
  12. # or $ANDROID_NDK/build/cmake/android-legacy.toolchain.cmake for ndk >= r23
  13. #
  14. # delete "-g" line
  15. #
  16. # list(APPEND ANDROID_COMPILER_FLAGS
  17. # -g
  18. # -DANDROID
  19. if [ -z $ANDROID_NDK ]; then
  20. ANDROID_NDK=/ceph-fj/fangjun/software/android-sdk/ndk/21.0.6113669
  21. # or use
  22. # ANDROID_NDK=/ceph-fj/fangjun/software/android-ndk
  23. #
  24. # Inside the $ANDROID_NDK directory, you can find a binary ndk-build
  25. # and some other files like the file "build/cmake/android.toolchain.cmake"
  26. if [ ! -d $ANDROID_NDK ]; then
  27. # For macOS, I have installed Android Studio, select the menu
  28. # Tools -> SDK manager -> Android SDK
  29. # and set "Android SDK location" to /Users/fangjun/software/my-android
  30. ANDROID_NDK=/Users/fangjun/software/my-android/ndk/22.1.7171670
  31. fi
  32. fi
  33. if [ ! -d $ANDROID_NDK ]; then
  34. echo Please set the environment variable ANDROID_NDK before you run this script
  35. exit 1
  36. fi
  37. echo "ANDROID_NDK: $ANDROID_NDK"
  38. sleep 1
  39. cmake -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
  40. -DCMAKE_BUILD_TYPE=Release \
  41. -DBUILD_SHARED_LIBS=ON \
  42. -DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
  43. -DSHERPA_NCNN_ENABLE_BINARY=OFF \
  44. -DSHERPA_NCNN_ENABLE_TEST=OFF \
  45. -DSHERPA_NCNN_ENABLE_C_API=OFF \
  46. -DSHERPA_NCNN_ENABLE_GENERATE_INT8_SCALE_TABLE=OFF \
  47. -DCMAKE_INSTALL_PREFIX=./install \
  48. -DANDROID_ABI="x86_64" \
  49. -DANDROID_PLATFORM=android-21 ..
  50. make VERBOSE=1 -j4
  51. make install/strip