diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 65623c7821ab301f3eec11dfb1c9ef8f6568289a..677bedf8fe1af78c73a362d388bdafdbbc8ff791 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -136,4 +136,4 @@ model_tests: build_android_demo: stage: build_android_demo script: - - pushd mace/examples/android/ && bash build.sh build && popd + - pushd mace/examples/android/ && bash build.sh static && bash build.sh dynamic && popd diff --git a/mace/codegen/BUILD b/mace/codegen/BUILD index 5122da1dac77fc5d28ba92930267a6d87b6eccad..8a24594c15662dcb04d1c10772000acc0488f835 100644 --- a/mace/codegen/BUILD +++ b/mace/codegen/BUILD @@ -50,7 +50,6 @@ cc_library( copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], deps = [ "//mace/public", - "//mace/utils", ], ) diff --git a/mace/utils/status.cc b/mace/core/status.cc similarity index 100% rename from mace/utils/status.cc rename to mace/core/status.cc diff --git a/mace/examples/android/README.md b/mace/examples/android/README.md index 5edfff76050c2e904ce1afa69a6518e81b281077..5d2154901a7bd7e270fa67ec5eeaa818459b8d9c 100644 --- a/mace/examples/android/README.md +++ b/mace/examples/android/README.md @@ -6,7 +6,16 @@ How to build ```sh cd mace/exampls/android -./build.sh +./build.sh dynamic +# if libmace.a is needed, update `macelibrary/CMakeLists.txt` and run with `./build.sh static`. +``` + +Install +--------------- + +```sh +# running after build step and in `mace/exampls/android` directory +adb install ./app/build/outputs/apk/app/release/app-app-release.apk ``` Pre-built APK diff --git a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java b/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java index 648c0fcac4691bda5f722003c3a3ca47361af57c..6ecf0d10631087b6203a301c699b3ec85fdd6152 100644 --- a/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java +++ b/mace/examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/CameraApiLessM.java @@ -105,12 +105,11 @@ public class CameraApiLessM extends CameraEngage implements Camera.AutoFocusCall Camera.Parameters parameters = mCamera.getParameters(); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); Camera.Size size = getOptimalSize(parameters.getSupportedPreviewSizes(), width, height); - mPreviewWidth = size.width; - mPreviewHeight = size.height; + mPreviewWidth = size.height; + mPreviewHeight = size.width; parameters.setPreviewSize(size.width, size.height); - parameters.setPictureSize(size.width, size.height); mCamera.setParameters(parameters); - mTextureView.setRatio(size.height, size.width); + mTextureView.setRatio(mPreviewWidth, mPreviewHeight); } private Camera.Size getOptimalSize(List sizes, int w, int h) { diff --git a/mace/examples/android/build.sh b/mace/examples/android/build.sh index 1cfb6129e104c61561a20532a586278232b1c467..4bbb177d406df158ad839c59ba122bf0c082df68 100755 --- a/mace/examples/android/build.sh +++ b/mace/examples/android/build.sh @@ -2,12 +2,47 @@ set -e -u -o pipefail +Usage() { + echo "Usage: ./build.sh [dynamic|static]" + echo "|==============|====================|" + echo "| parameter | lib will linked |" + echo "|==============|====================|" + echo "| dynamic | libmace.so |" + echo "|--------------|--------------------|" + echo "| static | libmace.a |" + echo "|--------------|--------------------|" +} + +if [ $# -lt 1 ]; then + Usage + exit 1 +fi + +MACE_LINK_TYPE=$1 + pushd ../../../ TARGET_ABI=arm64-v8a -LIBRARY_DIR=mace/examples/android/macelibrary/src/main/cpp/ +ANDROID_DEMO_DIR=mace/examples/android/ +LIBRARY_DIR=$ANDROID_DEMO_DIR/macelibrary/src/main/cpp/ INCLUDE_DIR=$LIBRARY_DIR/include/mace/public/ LIBMACE_DIR=$LIBRARY_DIR/lib/$TARGET_ABI/ +LIBGNUSTL_SHARED_SO=libgnustl_shared.so +LIBCPP_SHARED_SO=libc++_shared.so + +JNILIBS_DIR=$ANDROID_DEMO_DIR/macelibrary/src/main/jniLibs/$TARGET_ABI +rm -rf $JNILIBS_DIR + +if [ $MACE_LINK_TYPE == "dynamic" ]; then + BAZEL_LIBMACE_TARGET=mace/libmace:libmace.so + BAZEL_GEN_LIBMACE_PATH=bazel-bin/mace/libmace/libmace.so +elif [ $MACE_LINK_TYPE == "static" ]; then + BAZEL_LIBMACE_TARGET=mace/libmace:libmace_static + BAZEL_GEN_LIBMACE_PATH=bazel-genfiles/mace/libmace/libmace.a +else + Usage + exit 1 +fi rm -rf $LIBRARY_DIR/include/ mkdir -p $INCLUDE_DIR @@ -21,14 +56,25 @@ python tools/converter.py convert --config=mace/examples/android/mobilenet.yml - cp -rf builds/mobilenet/include/mace/public/*.h $INCLUDE_DIR cp -rf builds/mobilenet/model $LIBRARY_DIR -bazel build --config android --config optimization mace/libmace:libmace_static --define neon=true --define openmp=true --define opencl=true --cpu=$TARGET_ABI +bazel build --config android --config optimization $BAZEL_LIBMACE_TARGET --define neon=true --define openmp=true --define opencl=true --cpu=$TARGET_ABI cp -rf mace/public/*.h $INCLUDE_DIR -cp -rf bazel-genfiles/mace/libmace/libmace.a $LIBMACE_DIR +cp -rf $BAZEL_GEN_LIBMACE_PATH $LIBMACE_DIR -popd +if [ $MACE_LINK_TYPE == "dynamic" ]; then + mkdir -p $JNILIBS_DIR + cp -rf $BAZEL_GEN_LIBMACE_PATH $JNILIBS_DIR -if [ $# -eq 1 ] && [ $1 == "build" ]; then - ./gradlew build -else - ./gradlew installAppRelease + if [[ "" != `$ANDROID_NDK_HOME/ndk-depends $BAZEL_GEN_LIBMACE_PATH | grep $LIBGNUSTL_SHARED_SO` ]]; then + cp -rf $ANDROID_NDK_HOME/sources/cxx-stl/gnu-libstdc++/4.9/libs/$TARGET_ABI/$LIBGNUSTL_SHARED_SO $JNILIBS_DIR + fi + + if [[ "" != `$ANDROID_NDK_HOME/ndk-depends $BAZEL_GEN_LIBMACE_PATH | grep $LIBCPP_SHARED_SO` ]]; then + cp -rf $ANDROID_NDK_HOME/sources/cxx-stl/llvm-libc++/libs/$TARGET_ABI/$LIBCPP_SHARED_SO $JNILIBS_DIR + fi fi + +popd + +# Build demo +./gradlew clean +./gradlew build diff --git a/mace/examples/android/macelibrary/CMakeLists.txt b/mace/examples/android/macelibrary/CMakeLists.txt index fbdb60c55f94a5c83882f2e525b525ef51a21018..d91f77371381b1881cb96fbc5bfd5a2e56178f2f 100644 --- a/mace/examples/android/macelibrary/CMakeLists.txt +++ b/mace/examples/android/macelibrary/CMakeLists.txt @@ -14,9 +14,10 @@ cmake_minimum_required(VERSION 3.4.1) include_directories(${CMAKE_SOURCE_DIR}/) include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include) -set(mace_lib ${CMAKE_SOURCE_DIR}/src/main/cpp/lib/arm64-v8a/libmace.a) +file(GLOB LIBMACE "${CMAKE_SOURCE_DIR}/src/main/cpp/lib/arm64-v8a/*") +set(mace_lib ${LIBMACE}) set(mobilenet_lib ${CMAKE_SOURCE_DIR}/src/main/cpp/model/arm64-v8a/mobilenet.a) -add_library (mace_lib STATIC IMPORTED) +add_library (mace_lib SHARED IMPORTED) set_target_properties(mace_lib PROPERTIES IMPORTED_LOCATION ${mace_lib}) add_library (mobilenet_lib STATIC IMPORTED) set_target_properties(mobilenet_lib PROPERTIES IMPORTED_LOCATION ${mobilenet_lib}) @@ -49,8 +50,8 @@ find_library( # Sets the name of the path variable. target_link_libraries( # Specifies the target library. mace_mobile_jni - mace_lib mobilenet_lib + mace_lib # Links the target library to the log library # included in the NDK. - ${log-lib} ) \ No newline at end of file + ${log-lib} ) diff --git a/mace/libmace/mace_version_script.lds b/mace/libmace/mace_version_script.lds index 424cef31b2ed2def8b00acfe29eee6ceeb1a4b53..04e88455f67c209c0e6c7d70cce12167a81fbad5 100644 --- a/mace/libmace/mace_version_script.lds +++ b/mace/libmace/mace_version_script.lds @@ -10,6 +10,7 @@ mace { # api for static library of models *mace*logging*LogMessage*; + *mace*MaceStatus*; *mace*NetDef*; *mace*MemoryType*; *mace*DataType*; diff --git a/mace/utils/BUILD b/mace/utils/BUILD index 6d6feb1a52736368198b11700de9493f65af44a6..283efa490e0a54ed48df9a61a289e5b67bf503f8 100644 --- a/mace/utils/BUILD +++ b/mace/utils/BUILD @@ -13,7 +13,6 @@ cc_library( name = "utils", srcs = [ "logging.cc", - "status.cc", "string_util.cc", ], hdrs = glob([