mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
add install step and docs for Android build (#17298)
Summary: This commit did below enhancements: 1, add doc for build_android.sh; 2, add install step for build_android.sh, thus the headers and libraries can be collected together for further usage conveniently; 3, change the default INSTALL_PREFIX from $PYTORCH_ROOT/install to $PYTORCH_ROOT/build_android/install to make the project directory clean. Pull Request resolved: https://github.com/pytorch/pytorch/pull/17298 Differential Revision: D14149709 Pulled By: soumith fbshipit-source-id: a3a38cb41f26377e21aa89e49e57e8f21c9c1a39
This commit is contained in:
parent
1b3315ec17
commit
c3a23379ea
23
scripts/README.md
Normal file
23
scripts/README.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
This directory contains the usful tools.
|
||||
|
||||
|
||||
## build_android.sh
|
||||
This script is to build PyTorch/Caffe2 library for Android. Take following steps to start the build:
|
||||
|
||||
- set ANDROID_NDK to the location of ndk
|
||||
|
||||
```bash
|
||||
export ANDROID_NDK=YOUR_NDK_PATH
|
||||
```
|
||||
|
||||
- run build_android.sh
|
||||
```bash
|
||||
#in your PyTorch root directory
|
||||
bash scripts/build_android.sh
|
||||
```
|
||||
If succeeded, the libraries and headers would be generated to build_android/install directory. You can then copy these files from build_android/install to your Android project for further usage.
|
||||
|
||||
You can also override the cmake flags via command line, e.g., following command will also compile the executable binary files:
|
||||
```bash
|
||||
bash scripts/build_android.sh -DBUILD_BINARY=ON
|
||||
```
|
||||
|
|
@ -21,8 +21,12 @@
|
|||
|
||||
set -e
|
||||
|
||||
CAFFE2_ROOT="$( cd "$(dirname "$0")"/.. ; pwd -P)"
|
||||
# Android specific flags
|
||||
ANDROID_ABI="armeabi-v7a with NEON"
|
||||
ANDROID_NATIVE_API_LEVEL="21"
|
||||
echo "Build with ANDROID_ABI[$ANDROID_ABI], ANDROID_NATIVE_API_LEVEL[$ANDROID_NATIVE_API_LEVEL]"
|
||||
|
||||
CAFFE2_ROOT="$( cd "$(dirname "$0")"/.. ; pwd -P)"
|
||||
if [ -z "$ANDROID_NDK" ]; then
|
||||
echo "ANDROID_NDK not set; please set it to the Android NDK directory"
|
||||
exit 1
|
||||
|
|
@ -43,6 +47,7 @@ $CAFFE2_ROOT/scripts/build_host_protoc.sh
|
|||
|
||||
# Now, actually build the Android target.
|
||||
BUILD_ROOT=${BUILD_ROOT:-"$CAFFE2_ROOT/build_android"}
|
||||
INSTALL_PREFIX=${BUILD_ROOT}/install
|
||||
mkdir -p $BUILD_ROOT
|
||||
cd $BUILD_ROOT
|
||||
|
||||
|
|
@ -74,7 +79,6 @@ CMAKE_ARGS+=("-DUSE_LMDB=OFF")
|
|||
CMAKE_ARGS+=("-DUSE_LEVELDB=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_MPI=OFF")
|
||||
CMAKE_ARGS+=("-DUSE_OPENMP=OFF")
|
||||
|
||||
# Only toggle if VERBOSE=1
|
||||
if [ "${VERBOSE:-}" == '1' ]; then
|
||||
CMAKE_ARGS+=("-DCMAKE_VERBOSE_MAKEFILE=1")
|
||||
|
|
@ -82,15 +86,15 @@ fi
|
|||
|
||||
# Android specific flags
|
||||
CMAKE_ARGS+=("-DANDROID_NDK=$ANDROID_NDK")
|
||||
CMAKE_ARGS+=("-DANDROID_ABI=armeabi-v7a with NEON")
|
||||
CMAKE_ARGS+=("-DANDROID_NATIVE_API_LEVEL=21")
|
||||
CMAKE_ARGS+=("-DANDROID_ABI=$ANDROID_ABI")
|
||||
CMAKE_ARGS+=("-DANDROID_NATIVE_API_LEVEL=$ANDROID_NATIVE_API_LEVEL")
|
||||
CMAKE_ARGS+=("-DANDROID_CPP_FEATURES=rtti exceptions")
|
||||
|
||||
# Use-specified CMake arguments go last to allow overridding defaults
|
||||
CMAKE_ARGS+=($@)
|
||||
|
||||
cmake "$CAFFE2_ROOT" \
|
||||
-DCMAKE_INSTALL_PREFIX=../install \
|
||||
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
"${CMAKE_ARGS[@]}"
|
||||
|
||||
|
|
@ -103,3 +107,8 @@ if [ -z "$MAX_JOBS" ]; then
|
|||
fi
|
||||
fi
|
||||
cmake --build . -- "-j${MAX_JOBS}"
|
||||
|
||||
# copy headers and libs to install directory
|
||||
echo "Will install headers and libs to $INSTALL_PREFIX for further Android project usage."
|
||||
make install
|
||||
echo "Installation completed, now you can copy the headers/libs from $INSTALL_PREFIX to your Android project directory."
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user