Fix android build when API<23, fix android test, update build doc and pipeline (#884)

This commit is contained in:
daquexian 2019-05-25 07:26:32 +08:00 committed by Ke Zhang
parent 2d92b95729
commit ea29a664cd
5 changed files with 21 additions and 6 deletions

View file

@ -326,3 +326,17 @@ ls -l /code/onnxruntime/build/Linux/MinSizeRel/dist/*.whl
### Using other compilers
(TODO)
## Android Builds
### Cross compiling on Linux
1. Get Android NDK from https://developer.android.com/ndk/downloads. Please unzip it after downloading.
2. Get a pre-compiled protoc:
You may get it from https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip. Please unzip it after downloading.
3. Denote the unzip destination in step 1 as $ANDROID_NDK, append `-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DONNX_CUSTOM_PROTOC_EXECUTABLE=path/to/protoc` to your cmake args, run cmake and make to build it.
Note: For 32-bit devices, replace `-DANDROID_ABI=arm64-v8a` to `-DANDROID_ABI=armeabi-v7a`.

View file

@ -236,7 +236,7 @@ void LoopDir(const std::string& dir_name, T func) {
auto e = errno;
char buf[1024];
char* msg;
#if defined(__GLIBC__) && defined(_GNU_SOURCE)
#if defined(__GLIBC__) && defined(_GNU_SOURCE) && !defined (__ANDROID__)
msg = strerror_r(e, buf, sizeof(buf));
#else
if (strerror_r(e, buf, sizeof(buf)) != 0) {
@ -270,4 +270,4 @@ inline T ReplaceFilename(const T& input, const T& new_value) {
return ConcatPathComponent(ret, new_value);
}
} // namespace onnxruntime
} // namespace onnxruntime

View file

@ -180,9 +180,10 @@ class PosixEnv : public Env {
char buf[1024];
const char* msg = "";
if (e > 0) {
#if defined(__GLIBC__) && defined(_GNU_SOURCE)
#if defined(__GLIBC__) && defined(_GNU_SOURCE) && !defined (__ANDROID__)
msg = strerror_r(e, buf, sizeof(buf));
#else
// for Mac OS X and Android lower than API 23
if (strerror_r(e, buf, sizeof(buf)) != 0) {
buf[0] = '\0';
}

View file

@ -246,7 +246,7 @@ TEST(Random, MultinomialGoodCase) {
const std::vector<int64_t> output_dims{batch_size, num_samples};
#ifdef _WIN32
const std::vector<int64_t> expected_output{2, 0, 0, 2, 2, 2, 0, 2, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, 0};
#elif defined(__MACH__)
#elif defined(__MACH__) || defined (__ANDROID__)
const std::vector<int64_t> expected_output{1, 1, 2, 2, 0, 2, 2, 2, 0, 2, 1, 1, 2, 0, 2, 2, 0, 2, 1, 1};
#else
const std::vector<int64_t> expected_output{2, 0, 0, 1, 0, 1, 2, 0, 1, 0, 0, 1, 1, 0, 1, 0, 2, 0, 2, 0};
@ -274,7 +274,7 @@ TEST(Random, MultinomialDefaultDType) {
const std::vector<int64_t> output_dims{batch_size, num_samples};
#ifdef _WIN32
const std::vector<int32_t> expected_output{2, 0, 0, 2, 2, 2, 0, 2, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, 0};
#elif defined(__MACH__)
#elif defined(__MACH__) || defined (__ANDROID__)
const std::vector<int32_t> expected_output{1, 1, 2, 2, 0, 2, 2, 2, 0, 2, 1, 1, 2, 0, 2, 2, 0, 2, 1, 1};
#else
const std::vector<int32_t> expected_output{2, 0, 0, 1, 0, 1, 2, 0, 1, 0, 0, 1, 1, 0, 1, 0, 2, 0, 2, 0};

View file

@ -17,7 +17,7 @@ done
if [ $BUILD_OS = "android" ]; then
pushd /onnxruntime_src
mkdir build-android && cd build-android
/opt/cmake/bin/cmake -DCMAKE_TOOLCHAIN_FILE=/android-ndk/build/cmake/android.toolchain.cmake -DANDROID_CPP_FEATURES=exceptions -DANDROID_PLATFORM=android-28 -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release -Donnxruntime_CROSS_COMPILING=ON -Donnxruntime_BUILD_x86=OFF -DONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc ../cmake
/opt/cmake/bin/cmake -DCMAKE_TOOLCHAIN_FILE=/android-ndk/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DONNX_CUSTOM_PROTOC_EXECUTABLE=/usr/bin/protoc ../cmake
/opt/cmake/bin/cmake --build . -- -j$(nproc)
else
COMMON_BUILD_ARGS="--skip_submodule_sync --enable_onnx_tests --parallel --build_shared_lib --use_openmp"