Skip to content

Commit

Permalink
optimize JNI lib size
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed Mar 27, 2024
1 parent 5eea3b0 commit eeccc9f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ project(ot-commissioner VERSION 0.2.0)

option(OT_COMM_ANDROID "Build with Android NDK" OFF)
option(OT_COMM_APP "Build the CLI App" ON)
option(OT_COMM_CCM "Build with Commercial Commissioning Mode" ON)
option(OT_COMM_CCM "Build with Commercial Commissioning Mode" OFF)
option(OT_COMM_REFERENCE_DEVICE "Enable features for being a Thread Group reference device" OFF)
option(OT_COMM_COVERAGE "Enable coverage reporting" OFF)
option(OT_COMM_JAVA_BINDING "Build Java binding" OFF)
set(OT_COMM_JAVA_BINDING_OUTDIR "" CACHE STRING "Specify output directory of generated Java source files")
option(OT_COMM_TEST "Build tests" ON)
option(OT_COMM_TEST "Build tests" OFF)
option(OT_COMM_WARNING_AS_ERROR "Treat warning as error" OFF)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
endif()

if(NOT "${CMAKE_CXX_STANDARD}")
Expand Down
8 changes: 5 additions & 3 deletions android/build-commissioner-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ cmake -GNinja \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DOT_COMM_ANDROID=ON \
-DOT_COMM_JAVA_BINDING=ON \
-DOT_COMM_APP=OFF \
-DOT_COMM_TEST=OFF \
-DOT_COMM_CCM=OFF \
-DCMAKE_C_FLAGS="-Os -g0 -DNDEBUG" \
-DCMAKE_CXX_FLAGS="-Os -g0 -DNDEBUG" \
../..

ninja commissioner-java
Expand All @@ -75,9 +77,9 @@ find ./io/openthread/commissioner -name "*.class" | xargs jar cvf ../../libs/lib
cd ../../../

## Copy shared native libraries
cp "$BUILD_DIR"/src/java/libcommissioner-java.so "$BUILD_DIR"/libs
cp "$BUILD_DIR"/src/java/libcommissioner-java.a "$BUILD_DIR"/libs

mkdir -p openthread_commissioner/service/libs
mkdir -p openthread_commissioner/service/src/main/jniLibs/"${ANDROID_ABI}"
cp "$BUILD_DIR"/libs/libotcommissioner.jar openthread_commissioner/service/libs
cp "$BUILD_DIR"/libs/*.so openthread_commissioner/service/src/main/jniLibs/"${ANDROID_ABI}"
cp "$BUILD_DIR"/libs/libcommissioner-java.a openthread_commissioner/service/src/main/jniLibs/"${ANDROID_ABI}"
38 changes: 19 additions & 19 deletions src/common/error_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,42 @@
#define ERROR_NONE \
Error {}
#define ERROR_CANCELLED(aFormat, ...) \
Error { ErrorCode::kCancelled, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kCancelled, "" }
#define ERROR_INVALID_ARGS(aFormat, ...) \
Error { ErrorCode::kInvalidArgs, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kInvalidArgs, "" }
#define ERROR_INVALID_COMMAND(aFormat, ...) \
Error { ErrorCode::kInvalidCommand, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kInvalidCommand, "" }
#define ERROR_TIMEOUT(aFormat, ...) \
Error { ErrorCode::kTimeout, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kTimeout, "" }
#define ERROR_NOT_FOUND(aFormat, ...) \
Error { ErrorCode::kNotFound, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kNotFound, "" }
#define ERROR_SECURITY(aFormat, ...) \
Error { ErrorCode::kSecurity, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kSecurity, "" }
#define ERROR_UNIMPLEMENTED(aFormat, ...) \
Error { ErrorCode::kUnimplemented, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kUnimplemented, "" }
#define ERROR_BAD_FORMAT(aFormat, ...) \
Error { ErrorCode::kBadFormat, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kBadFormat, "" }
#define ERROR_BUSY(aFormat, ...) \
Error { ErrorCode::kBusy, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kBusy, "" }
#define ERROR_OUT_OF_MEMORY(aFormat, ...) \
Error { ErrorCode::kOutOfMemory, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kOutOfMemory, "" }
#define ERROR_IO_ERROR(aFormat, ...) \
Error { ErrorCode::kIOError, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kIOError, "" }
#define ERROR_IO_BUSY(aFormat, ...) \
Error { ErrorCode::kIOBusy, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kIOBusy, "" }
#define ERROR_ALREADY_EXISTS(aFormat, ...) \
Error { ErrorCode::kAlreadyExists, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kAlreadyExists, "" }
#define ERROR_ABORTED(aFormat, ...) \
Error { ErrorCode::kAborted, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kAborted, "" }
#define ERROR_INVALID_STATE(aFormat, ...) \
Error { ErrorCode::kInvalidState, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kInvalidState, "" }
#define ERROR_REJECTED(aFormat, ...) \
Error { ErrorCode::kRejected, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kRejected, "" }
#define ERROR_COAP_ERROR(aFormat, ...) \
Error { ErrorCode::kCoapError, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kCoapError, "" }
#define ERROR_REGISTRY_ERROR(aFormat, ...) \
Error { ErrorCode::kRegistryError, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kRegistryError, "" }
#define ERROR_UNKNOWN(aFormat, ...) \
Error { ErrorCode::kUnknown, fmt::format(FMT_STRING((aFormat)), ##__VA_ARGS__) }
Error { ErrorCode::kUnknown, "" }

#endif // ERROR_MACROS_HPP_
1 change: 0 additions & 1 deletion src/common/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#define LOG(aLevel, aRegion, aFmt, ...) \
do \
{ \
Log(aLevel, aRegion, fmt::format(FMT_STRING(aFmt), ##__VA_ARGS__)); \
} while (false)

#define LOG_DEBUG(aRegion, aFmt, ...) LOG(LogLevel::kDebug, aRegion, aFmt, ##__VA_ARGS__)
Expand Down
2 changes: 1 addition & 1 deletion src/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ set_property(SOURCE commissioner.i PROPERTY CPLUSPLUS ON)
set(UseSWIG_TARGET_NAME_PREFERENCE LEGACY)

swig_add_library(commissioner-java
TYPE SHARED
TYPE STATIC
LANGUAGE java
SOURCES commissioner.i)

Expand Down

0 comments on commit eeccc9f

Please sign in to comment.