mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Summary: 1. scripts/build_android_libtorch_and_pytorch_android.sh - Builds libtorch for android_abis (by default for all 4: x86, x86_64, armeabi-v7a, arm-v8a) but cab be specified only custom list as a first parameter e.g. "x86" - Creates symbolic links inside android/pytorch_android to results of the previous builds: `pytorch_android/src/main/jniLibs/${abi}` -> `build_android/install/lib` `pytorch_android/src/main/cpp/libtorch_include/${abi}` -> `build_android/install/include` - Runs gradle assembleRelease to build aar files proxy can be specified inside (for devservers) 2. android/run_tests.sh Running pytorch_android tests, contains instruction how to setup and run android emulator in headless and noaudio mode to run it on devserver proxy can be specified inside (for devservers) #Test plan Scenario to build x86 libtorch and android aars with it and run tests: ``` cd pytorch sh scripts/build_android_libtorch_and_pytorch_android.sh x86 sh android/run_tests.sh ``` Tested on my devserver - build works, tests passed Pull Request resolved: https://github.com/pytorch/pytorch/pull/26833 Differential Revision: D17673972 Pulled By: IvanKobzarev fbshipit-source-id: 8cb7c3d131781854589de6428a7557c1ba7471e9
84 lines
2.2 KiB
Bash
Executable File
84 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -eux
|
|
|
|
PYTORCH_DIR="$(cd $(dirname $0)/..; pwd -P)"
|
|
PYTORCH_ANDROID_DIR=$PYTORCH_DIR/android
|
|
|
|
echo "ANDROID_HOME:$ANDROID_HOME"
|
|
if [ ! -z "$ANDROID_HOME" ]; then
|
|
echo "ANDROID_HOME not set; please set it to Android sdk directory"
|
|
fi
|
|
|
|
if [ ! -d $ANDROID_HOME ]; then
|
|
echo "ANDROID_HOME not a directory; did you install it under $ANDROID_HOME?"
|
|
exit 1
|
|
fi
|
|
|
|
echo "ANDROID_NDK:$ANDROID_NDK"
|
|
if [ ! -z "$ANDROID_NDK" ]; then
|
|
echo "ANDROID_NDK not set; please set it to Android sdk directory"
|
|
fi
|
|
|
|
if [ ! -d $ANDROID_NDK ]; then
|
|
echo "ANDROID_NDK not a directory; did you install it under $ANDROID_NDK?"
|
|
exit 1
|
|
fi
|
|
|
|
GRADLE_PATH=gradle
|
|
GRADLE_NOT_FOUND_MSG="Unable to find gradle, please add it to PATH or set GRADLE_HOME"
|
|
|
|
if [ ! -x "$(command -v gradle)" ]; then
|
|
if [ -z "$GRADLE_HOME" ]; then
|
|
echo GRADLE_NOT_FOUND_MSG
|
|
exit 1
|
|
fi
|
|
GRADLE_PATH=$GRADLE_HOME/bin/gradle
|
|
if [ ! -f "$GRADLE_PATH" ]; then
|
|
echo GRADLE_NOT_FOUND_MSG
|
|
exit 1
|
|
fi
|
|
fi
|
|
echo "GRADLE_PATH:$GRADLE_PATH"
|
|
|
|
|
|
# Run android instrumented tests on x86 emulator
|
|
|
|
ADB_PATH=$ANDROID_HOME/platform-tools/adb
|
|
|
|
echo "Expecting running emulator"
|
|
$ADB_PATH devices
|
|
|
|
DEVICES_COUNT=$($ADB_PATH devices | awk 'NF' | wc -l)
|
|
echo "DEVICES_COUNT:$DEVICES_COUNT"
|
|
|
|
if [ "$DEVICES_COUNT" -eq 1 ]; then
|
|
echo "Unable to found connected android emulators"
|
|
cat <<- EOF
|
|
To start android emulator:
|
|
1. Install android sdkmanager packages
|
|
$ANDROID_HOME/tools/bin/sdkmanager "system-images;android-25;google_apis;x86"
|
|
|
|
to specify proxy add params: --proxy=http --proxy_host=fwdproxy --proxy_port=8080
|
|
|
|
2. Create android virtual device
|
|
$ANDROID_HOME/tools/bin/avdmanager create avd --name "x86_android25" --package "system-images;android-25;google_apis;x86"
|
|
|
|
3. Start emulator in headless mode without audio
|
|
$ANDROID_HOME/tools/emulator -avd x86_android25 -no-audio -no-window
|
|
|
|
4. Check that emulator is running
|
|
$ANDROID_HOME/platform-tools/adb devices
|
|
|
|
If everything is ok the output will be:
|
|
|
|
List of devices attached
|
|
emulator-5554 device
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
echo "Waiting for emulator boot completed"
|
|
$ADB_PATH wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
|
|
|
|
$GRADLE_PATH -PABI_FILTERS=x86 -p $PYTORCH_ANDROID_DIR connectedAndroidTest
|