Skip to content

Commit

Permalink
Add no_samples_build option to Android SDK build
Browse files Browse the repository at this point in the history
  • Loading branch information
komakai committed Jul 18, 2019
1 parent f6ec0cd commit a897fc9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ if(BUILD_opencv_apps)
endif()

# examples
if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES OR INSTALL_C_EXAMPLES)
if(BUILD_EXAMPLES OR BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES OR INSTALL_PYTHON_EXAMPLES OR INSTALL_C_EXAMPLES)
add_subdirectory(samples)
endif()

Expand Down Expand Up @@ -1199,7 +1199,7 @@ ocv_build_features_string(apps_status
IF BUILD_EXAMPLES THEN "examples"
IF BUILD_opencv_apps THEN "apps"
IF BUILD_ANDROID_SERVICE THEN "android_service"
IF BUILD_ANDROID_EXAMPLES AND CAN_BUILD_ANDROID_PROJECTS THEN "android_examples"
IF (BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES) AND CAN_BUILD_ANDROID_PROJECTS THEN "android_examples"
ELSE "-")
status(" Applications:" "${apps_status}")
ocv_build_features_string(docs_status
Expand Down
34 changes: 23 additions & 11 deletions cmake/android/android_gradle_projects.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,29 @@ macro(add_android_project target path)
include ':${__dir}'
")

# build apk
set(APK_FILE "${ANDROID_BUILD_BASE_DIR}/${__dir}/build/outputs/apk/release/${__dir}-${ANDROID_ABI}-release-unsigned.apk")
ocv_update(OPENCV_GRADLE_VERBOSE_OPTIONS "-i")
add_custom_command(
OUTPUT "${APK_FILE}" "${OPENCV_DEPHELPER}/android_sample_${__dir}"
COMMAND ./gradlew ${OPENCV_GRADLE_VERBOSE_OPTIONS} "${__dir}:assemble"
COMMAND ${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/android_sample_${__dir}"
WORKING_DIRECTORY "${ANDROID_BUILD_BASE_DIR}"
DEPENDS ${depends} opencv_java_android
COMMENT "Building OpenCV Android sample project: ${__dir}"
)
if (BUILD_ANDROID_EXAMPLES)
# build apk
set(APK_FILE "${ANDROID_BUILD_BASE_DIR}/${__dir}/build/outputs/apk/release/${__dir}-${ANDROID_ABI}-release-unsigned.apk")
ocv_update(OPENCV_GRADLE_VERBOSE_OPTIONS "-i")
add_custom_command(
OUTPUT "${APK_FILE}" "${OPENCV_DEPHELPER}/android_sample_${__dir}"
COMMAND ./gradlew ${OPENCV_GRADLE_VERBOSE_OPTIONS} "${__dir}:assemble"
COMMAND ${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/android_sample_${__dir}"
WORKING_DIRECTORY "${ANDROID_BUILD_BASE_DIR}"
DEPENDS ${depends} opencv_java_android
COMMENT "Building OpenCV Android sample project: ${__dir}"
)
else() # install only
# copy samples
add_custom_command(
OUTPUT "${OPENCV_DEPHELPER}/android_sample_${__dir}"
COMMAND ${CMAKE_COMMAND} -E touch "${OPENCV_DEPHELPER}/android_sample_${__dir}"
WORKING_DIRECTORY "${ANDROID_BUILD_BASE_DIR}"
DEPENDS ${depends} opencv_java_android
COMMENT "Copying OpenCV Android sample project: ${__dir}"
)
endif()

file(REMOVE "${OPENCV_DEPHELPER}/android_sample_${__dir}") # force rebuild after CMake run

add_custom_target(android_sample_${__dir} ALL DEPENDS "${OPENCV_DEPHELPER}/android_sample_${__dir}" SOURCES "${ANDROID_SAMPLE_MANIFEST_PATH}")
Expand Down
11 changes: 8 additions & 3 deletions platforms/android/build_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def __init__(self, workdir, opencvdir, config):
self.ninja_path = self.get_ninja()
self.debug = True if config.debug else False
self.debug_info = True if config.debug_info else False
self.no_samples_build = True if config.no_samples_build else False

def get_cmake(self):
if not self.config.use_android_buildtools and check_executable(['cmake', '--version']):
Expand Down Expand Up @@ -217,7 +218,7 @@ def build_library(self, abi, do_install):
BUILD_TESTS="OFF",
BUILD_PERF_TESTS="OFF",
BUILD_DOCS="OFF",
BUILD_ANDROID_EXAMPLES="ON",
BUILD_ANDROID_EXAMPLES=("OFF" if self.no_samples_build else "ON"),
INSTALL_ANDROID_EXAMPLES="ON",
)
if self.ninja_path != 'ninja':
Expand All @@ -243,8 +244,11 @@ def build_library(self, abi, do_install):
execute(cmd)
# 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_info or self.debug) else "install/strip"])
# limit parallelism for building samples (avoid huge memory consumption)
if self.no_samples_build:
execute([self.ninja_path, "install" if (self.debug_info or self.debug) else "install/strip"])
else:
execute([self.ninja_path, "-j1" if (self.debug_info or self.debug) else "-j3", "install" if (self.debug_info or self.debug) else "install/strip"])

def build_javadoc(self):
classpaths = []
Expand Down Expand Up @@ -323,6 +327,7 @@ def gather_results(self):
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 '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)")
parser.add_argument('--no_samples_build', action="store_true", help="Do not build samples (speeds up build)")
args = parser.parse_args()

log.basicConfig(format='%(message)s', level=log.DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion platforms/android/gradle-wrapper/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
org.gradle.jvmargs=-Xmx2g

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
2 changes: 1 addition & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif()
if(UNIX AND NOT ANDROID AND (HAVE_VA OR HAVE_VA_INTEL))
add_subdirectory(va_intel)
endif()
if(ANDROID AND BUILD_ANDROID_EXAMPLES)
if(ANDROID AND (BUILD_ANDROID_EXAMPLES OR INSTALL_ANDROID_EXAMPLES))
add_subdirectory(android)
endif()
if(INSTALL_PYTHON_EXAMPLES)
Expand Down

0 comments on commit a897fc9

Please sign in to comment.