提交 13541b1a 编写于 作者: Y yejianwu

support dynamic load libmace in demo

上级 659e93ba
...@@ -136,4 +136,4 @@ model_tests: ...@@ -136,4 +136,4 @@ model_tests:
build_android_demo: build_android_demo:
stage: build_android_demo stage: build_android_demo
script: script:
- pushd mace/examples/android/ && bash build.sh build && popd - pushd mace/examples/android/ && bash build.sh static && bash build.sh dynamic && popd
...@@ -50,7 +50,6 @@ cc_library( ...@@ -50,7 +50,6 @@ cc_library(
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"],
deps = [ deps = [
"//mace/public", "//mace/public",
"//mace/utils",
], ],
) )
......
...@@ -6,7 +6,16 @@ How to build ...@@ -6,7 +6,16 @@ How to build
```sh ```sh
cd mace/exampls/android 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 Pre-built APK
......
...@@ -105,12 +105,11 @@ public class CameraApiLessM extends CameraEngage implements Camera.AutoFocusCall ...@@ -105,12 +105,11 @@ public class CameraApiLessM extends CameraEngage implements Camera.AutoFocusCall
Camera.Parameters parameters = mCamera.getParameters(); Camera.Parameters parameters = mCamera.getParameters();
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
Camera.Size size = getOptimalSize(parameters.getSupportedPreviewSizes(), width, height); Camera.Size size = getOptimalSize(parameters.getSupportedPreviewSizes(), width, height);
mPreviewWidth = size.width; mPreviewWidth = size.height;
mPreviewHeight = size.height; mPreviewHeight = size.width;
parameters.setPreviewSize(size.width, size.height); parameters.setPreviewSize(size.width, size.height);
parameters.setPictureSize(size.width, size.height);
mCamera.setParameters(parameters); mCamera.setParameters(parameters);
mTextureView.setRatio(size.height, size.width); mTextureView.setRatio(mPreviewWidth, mPreviewHeight);
} }
private Camera.Size getOptimalSize(List<Camera.Size> sizes, int w, int h) { private Camera.Size getOptimalSize(List<Camera.Size> sizes, int w, int h) {
......
...@@ -2,12 +2,47 @@ ...@@ -2,12 +2,47 @@
set -e -u -o pipefail 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 ../../../ pushd ../../../
TARGET_ABI=arm64-v8a 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/ INCLUDE_DIR=$LIBRARY_DIR/include/mace/public/
LIBMACE_DIR=$LIBRARY_DIR/lib/$TARGET_ABI/ 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/ rm -rf $LIBRARY_DIR/include/
mkdir -p $INCLUDE_DIR mkdir -p $INCLUDE_DIR
...@@ -21,14 +56,25 @@ python tools/converter.py convert --config=mace/examples/android/mobilenet.yml - ...@@ -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/include/mace/public/*.h $INCLUDE_DIR
cp -rf builds/mobilenet/model $LIBRARY_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 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 if [[ "" != `$ANDROID_NDK_HOME/ndk-depends $BAZEL_GEN_LIBMACE_PATH | grep $LIBGNUSTL_SHARED_SO` ]]; then
./gradlew build cp -rf $ANDROID_NDK_HOME/sources/cxx-stl/gnu-libstdc++/4.9/libs/$TARGET_ABI/$LIBGNUSTL_SHARED_SO $JNILIBS_DIR
else fi
./gradlew installAppRelease
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 fi
popd
# Build demo
./gradlew clean
./gradlew build
...@@ -14,9 +14,10 @@ cmake_minimum_required(VERSION 3.4.1) ...@@ -14,9 +14,10 @@ cmake_minimum_required(VERSION 3.4.1)
include_directories(${CMAKE_SOURCE_DIR}/) include_directories(${CMAKE_SOURCE_DIR}/)
include_directories(${CMAKE_SOURCE_DIR}/src/main/cpp/include) 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) 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}) set_target_properties(mace_lib PROPERTIES IMPORTED_LOCATION ${mace_lib})
add_library (mobilenet_lib STATIC IMPORTED) add_library (mobilenet_lib STATIC IMPORTED)
set_target_properties(mobilenet_lib PROPERTIES IMPORTED_LOCATION ${mobilenet_lib}) set_target_properties(mobilenet_lib PROPERTIES IMPORTED_LOCATION ${mobilenet_lib})
...@@ -49,8 +50,8 @@ find_library( # Sets the name of the path variable. ...@@ -49,8 +50,8 @@ find_library( # Sets the name of the path variable.
target_link_libraries( # Specifies the target library. target_link_libraries( # Specifies the target library.
mace_mobile_jni mace_mobile_jni
mace_lib
mobilenet_lib mobilenet_lib
mace_lib
# Links the target library to the log library # Links the target library to the log library
# included in the NDK. # included in the NDK.
${log-lib} ) ${log-lib} )
\ No newline at end of file
...@@ -10,6 +10,7 @@ mace { ...@@ -10,6 +10,7 @@ mace {
# api for static library of models # api for static library of models
*mace*logging*LogMessage*; *mace*logging*LogMessage*;
*mace*MaceStatus*;
*mace*NetDef*; *mace*NetDef*;
*mace*MemoryType*; *mace*MemoryType*;
*mace*DataType*; *mace*DataType*;
......
...@@ -13,7 +13,6 @@ cc_library( ...@@ -13,7 +13,6 @@ cc_library(
name = "utils", name = "utils",
srcs = [ srcs = [
"logging.cc", "logging.cc",
"status.cc",
"string_util.cc", "string_util.cc",
], ],
hdrs = glob([ hdrs = glob([
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册