Skip to content

Commit 133b91a

Browse files
committed
android: build fixes
- eliminate CMake 3.5+ warnings - removed usage of dropped "OPENCV_CAMERA_MODULES" variable - partial support for Android NDK 11+
1 parent 26be240 commit 133b91a

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

cmake/templates/OpenCV.mk.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ LOCAL_CFLAGS += $(OPENCV_LOCAL_CFLAGS)
9494
ifeq ($(OPENCV_INSTALL_MODULES),on)
9595
LOCAL_$(OPENCV_LIB_TYPE)_LIBRARIES += $(foreach mod, $(OPENCV_LIBS), opencv_$(mod))
9696
else
97+
$(call __ndk_info,OpenCV: You should ignore warning about 'non-system libraries in linker flags' and 'opencv_java' library.)
98+
$(call __ndk_info, 'OPENCV_INSTALL_MODULES:=on' can be used to build APK with included OpenCV binaries)
9799
LOCAL_LDLIBS += -L$(call host-path,$(LOCAL_PATH)/$(OPENCV_LIBS_DIR)) $(foreach lib, $(OPENCV_LIBS), -lopencv_$(lib))
98100
endif
99101

modules/java/android_lib/jni/Android.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ LOCAL_PATH := $(call my-dir)
22

33
include $(CLEAR_VARS)
44

5-
OPENCV_CAMERA_MODULES := off
65
include OpenCV.mk
76

87
LOCAL_MODULE := opencv_java

platforms/android/android.toolchain.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,10 @@ if( APPLE )
11501150
endif()
11511151

11521152
# Force set compilers because standard identification works badly for us
1153-
include( CMakeForceCompiler )
1154-
CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU )
1153+
if( CMAKE_VERSION VERSION_LESS 3.5.0 )
1154+
include( CMakeForceCompiler )
1155+
CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU )
1156+
endif()
11551157
if( ANDROID_COMPILER_IS_CLANG )
11561158
set( CMAKE_C_COMPILER_ID Clang )
11571159
endif()
@@ -1163,7 +1165,9 @@ else()
11631165
endif()
11641166
set( CMAKE_C_HAS_ISYSROOT 1 )
11651167
set( CMAKE_C_COMPILER_ABI ELF )
1166-
CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU )
1168+
if( CMAKE_VERSION VERSION_LESS 3.5.0 )
1169+
CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU )
1170+
endif()
11671171
if( ANDROID_COMPILER_IS_CLANG )
11681172
set( CMAKE_CXX_COMPILER_ID Clang)
11691173
endif()

platforms/android/build-tests/test_ndk_build.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def gen_android_mk(self):
7373
p = []
7474
if self.libtype == "static":
7575
p.append("OPENCV_LIB_TYPE := STATIC")
76-
elif self.libtype == "shared_debug":
76+
elif self.libtype == "shared":
7777
p.append("OPENCV_LIB_TYPE := SHARED")
78-
p.append("OPENCV_CAMERA_MODULES:=on")
7978
p.append("OPENCV_INSTALL_MODULES:=on")
80-
elif self.libtype == "shared":
79+
elif self.libtype == "shared_opencv_manager":
8180
p.append("OPENCV_LIB_TYPE := SHARED")
81+
p.append("OPENCV_INSTALL_MODULES:=off")
8282
p.append("include %s" % os.path.join(self.opencv_mk_path, "OpenCV.mk"))
8383
return TEMPLATE_ANDROID_MK.format(cut = "\n".join(p), cpp1 = self.cpp1, cpp2 = self.cpp2)
8484

@@ -115,14 +115,17 @@ def runTest(self):
115115
def suite(workdir, opencv_mk_path):
116116
abis = ["armeabi", "armeabi-v7a", "x86", "mips"]
117117
ndk_path = os.environ["ANDROID_NDK"]
118-
with open(os.path.join(ndk_path, "RELEASE.TXT"), "r") as f:
119-
s = f.read()
120-
if re.search(r'r10[b-e]', s):
121-
abis.extend(["arm64-v8a", "x86", "x86_64"])
118+
if os.path.exists(os.path.join(ndk_path, "RELEASE.TXT")):
119+
with open(os.path.join(ndk_path, "RELEASE.TXT"), "r") as f:
120+
s = f.read()
121+
if re.search(r'r10[b-e]', s):
122+
abis.extend(["arm64-v8a", "x86_64"])
123+
if os.path.exists(os.path.join(ndk_path, "source.properties")): # Android NDK 11+
124+
abis.extend(["arm64-v8a", "x86_64"])
122125
abis.append("all")
123126

124127
suite = unittest.TestSuite()
125-
for libtype in ["static", "shared", "shared_debug"]:
128+
for libtype in ["static", "shared", "shared_opencv_manager"]:
126129
for abi in abis:
127130
suite.addTest(TestNDKBuild(abi, libtype, opencv_mk_path, workdir))
128131
return suite

samples/android/face-detection/jni/Android.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ LOCAL_PATH := $(call my-dir)
22

33
include $(CLEAR_VARS)
44

5-
#OPENCV_CAMERA_MODULES:=off
65
#OPENCV_INSTALL_MODULES:=off
76
#OPENCV_LIB_TYPE:=SHARED
87
ifdef OPENCV_ANDROID_SDK

0 commit comments

Comments
 (0)