From 3c1267dbe62e83d65c80a7fa8cdf7e0b15c36c12 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sat, 18 May 2019 17:13:39 +0000 Subject: [PATCH] android: update 'debug' information support --- cmake/android/OpenCVDetectAndroidSDK.cmake | 3 ++- cmake/android/android_ant_projects.cmake | 4 +-- .../android_gradle_lib/build.gradle | 7 +++-- modules/java/android_sdk/build.gradle.in | 8 ++++++ modules/java/jni/CMakeLists.txt | 2 +- platforms/android/build_sdk.py | 8 ++++-- samples/android/build.gradle.in | 27 +++++++++++++++++++ 7 files changed, 51 insertions(+), 8 deletions(-) diff --git a/cmake/android/OpenCVDetectAndroidSDK.cmake b/cmake/android/OpenCVDetectAndroidSDK.cmake index 3a4ffefa43..3431d4aff8 100644 --- a/cmake/android/OpenCVDetectAndroidSDK.cmake +++ b/cmake/android/OpenCVDetectAndroidSDK.cmake @@ -9,7 +9,8 @@ if(DEFINED ANDROID_NDK_REVISION AND ANDROID_NDK_REVISION MATCHES "(1[56])([0-9]+ endif() # fixup -g option: https://github.com/opencv/opencv/issues/8460#issuecomment-434249750 -if((INSTALL_CREATE_DISTRIB OR CMAKE_BUILD_TYPE STREQUAL "Release") +if(INSTALL_CREATE_DISTRIB + AND (NOT BUILD_WITH_DEBUG_INFO AND NOT CMAKE_BUILD_TYPE MATCHES "Debug") AND NOT OPENCV_SKIP_ANDROID_G_OPTION_FIX ) if(" ${CMAKE_CXX_FLAGS} " MATCHES " -g ") diff --git a/cmake/android/android_ant_projects.cmake b/cmake/android/android_ant_projects.cmake index ed9ce43582..c098b7aa7d 100644 --- a/cmake/android/android_ant_projects.cmake +++ b/cmake/android/android_ant_projects.cmake @@ -201,8 +201,8 @@ macro(add_android_project target path) LIBRARY_OUTPUT_DIRECTORY "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}" ) - if (NOT (CMAKE_BUILD_TYPE MATCHES "debug")) - add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$") + if(NOT BUILD_WITH_DEBUG_INFO AND NOT CMAKE_BUILD_TYPE MATCHES "Debug") + add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$") endif() endif() endif() diff --git a/modules/java/android_sdk/android_gradle_lib/build.gradle b/modules/java/android_sdk/android_gradle_lib/build.gradle index acc4a60ec6..eea2fd4dea 100644 --- a/modules/java/android_sdk/android_gradle_lib/build.gradle +++ b/modules/java/android_sdk/android_gradle_lib/build.gradle @@ -11,11 +11,14 @@ android { buildTypes { debug { - packagingOptions{ - doNotStrip '*.so' + packagingOptions { + doNotStrip '**/*.so' // controlled by OpenCV CMake scripts } } release { + packagingOptions { + doNotStrip '**/*.so' // controlled by OpenCV CMake scripts + } minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } diff --git a/modules/java/android_sdk/build.gradle.in b/modules/java/android_sdk/build.gradle.in index fbb65bdfdf..a69719e8a3 100644 --- a/modules/java/android_sdk/build.gradle.in +++ b/modules/java/android_sdk/build.gradle.in @@ -102,7 +102,15 @@ android { } buildTypes { + debug { + packagingOptions { + doNotStrip '**/*.so' // controlled by OpenCV CMake scripts + } + } release { + packagingOptions { + doNotStrip '**/*.so' // controlled by OpenCV CMake scripts + } minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } diff --git a/modules/java/jni/CMakeLists.txt b/modules/java/jni/CMakeLists.txt index 2a50ee238e..c0cfbb3e1a 100644 --- a/modules/java/jni/CMakeLists.txt +++ b/modules/java/jni/CMakeLists.txt @@ -77,7 +77,7 @@ if(ANDROID) # force strip library after the build command # because samples and tests will make a copy of the library before install - if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + if(NOT BUILD_WITH_DEBUG_INFO AND NOT CMAKE_BUILD_TYPE MATCHES "Debug") add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$") endif() endif() diff --git a/platforms/android/build_sdk.py b/platforms/android/build_sdk.py index 9a95fc380e..fb7194b303 100755 --- a/platforms/android/build_sdk.py +++ b/platforms/android/build_sdk.py @@ -143,6 +143,7 @@ class Builder: self.cmake_path = self.get_cmake() self.ninja_path = self.get_ninja() self.debug = True if config.debug else False + self.debug_info = True if config.debug_info else False def get_cmake(self): if not self.config.use_android_buildtools and check_executable(['cmake', '--version']): @@ -217,6 +218,8 @@ class Builder: if self.debug: cmake_vars['CMAKE_BUILD_TYPE'] = "Debug" + + if self.debug_info: # Release with debug info cmake_vars['BUILD_WITH_DEBUG_INFO'] = "ON" if self.config.extra_modules_path is not None: @@ -234,7 +237,7 @@ class Builder: # full parallelism for C++ compilation tasks execute([self.ninja_path, "opencv_modules"]) # limit parallelism for Gradle steps (avoid huge memory consumption) - execute([self.ninja_path, '-j3', "install" if self.debug else "install/strip"]) + execute([self.ninja_path, '-j3', "install" if (self.debug_info or self.debug) else "install/strip"]) def build_javadoc(self): classpaths = [] @@ -291,7 +294,8 @@ if __name__ == "__main__": parser.add_argument('--no_ccache', action="store_true", help="Do not use ccache during library build") parser.add_argument('--force_copy', action="store_true", help="Do not use file move during library build (useful for debug)") parser.add_argument('--force_opencv_toolchain', action="store_true", help="Do not use toolchain from Android NDK") - parser.add_argument('--debug', action="store_true", help="Build for debug") + parser.add_argument('--debug', action="store_true", help="Build 'Debug' binaries (CMAKE_BUILD_TYPE=Debug)") + parser.add_argument('--debug_info', action="store_true", help="Build with debug information (useful for Release mode: BUILD_WITH_DEBUG_INFO=ON)") args = parser.parse_args() log.basicConfig(format='%(message)s', level=log.DEBUG) diff --git a/samples/android/build.gradle.in b/samples/android/build.gradle.in index 49a60e290e..e89eb911be 100644 --- a/samples/android/build.gradle.in +++ b/samples/android/build.gradle.in @@ -62,5 +62,32 @@ gradle.afterProject { project -> } } } + + // (you still need to re-build OpenCV with debug information to debug it) + if (true) { + gradle.println("Override doNotStrip-debug for the project ${project.name}") + project.android { + buildTypes { + debug { + packagingOptions { + doNotStrip '**/*.so' // controlled by OpenCV CMake scripts + } + } + } + } + } + if (false || project.hasProperty("doNotStrip")) { + gradle.println("Override doNotStrip-release for the project ${project.name}") + project.android { + buildTypes { + release { + packagingOptions { + doNotStrip '**/*.so' // controlled by OpenCV CMake scripts + } + } + } + } + } + } }