提交 051b213b 编写于 作者: 李滨

Merge branch 'support_so_in_demo' into 'master'

support dynamic load libmace in demo

See merge request !802
......@@ -135,4 +135,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
......@@ -50,7 +50,6 @@ cc_library(
copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"],
deps = [
"//mace/public",
"//mace/utils",
],
)
......
......@@ -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
......
......@@ -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<Camera.Size> sizes, int w, int h) {
......
......@@ -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
......@@ -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} )
......@@ -10,6 +10,7 @@ mace {
# api for static library of models
*mace*logging*LogMessage*;
*mace*MaceStatus*;
*mace*NetDef*;
*mace*MemoryType*;
*mace*DataType*;
......
......@@ -13,7 +13,6 @@ cc_library(
name = "utils",
srcs = [
"logging.cc",
"status.cc",
"string_util.cc",
],
hdrs = glob([
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册