最近搞之前的一份老代碼,發現OpenCV到2.4.11之後,之前的mk文件不適用了,報一堆一堆的錯誤。
一是如前文所述,LOCAL_LDLIBS += -lm -llog這一句+=絕不能錯誤的寫成:=.另外,還會報這樣一個錯誤:
Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersion 16 in ./AndroidManifest.xml Android NDK: WARNING:jni/Android.mk:ProcessImg: non-system libraries in linker flags: -lopencv_java Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the Android NDK: current module [armeabi-v7a] Compile++ thumb: ProcessImg <= DetectFace_JNI.cpp jni/DetectFace_JNI.cpp: In function '_jstring* Java_org_yan_processlib_LibProcessImg_processIplImg(JNIEnv*, jobject, jintArray, int, int)': jni/DetectFace_JNI.cpp:97:44: warning: converting 'false' to pointer type for argument 2 of 'jint* _JNIEnv::GetIntArrayElements(jintArray, jboolean*)' [-Wconversion-null] cbuf = env->GetIntArrayElements(buf, false); ^ jni/DetectFace_JNI.cpp: In function '_jstring* Java_org_yan_processlib_LibProcessImg_processStaticImg(JNIEnv*, jobject, jintArray, int, int)': jni/DetectFace_JNI.cpp:131:44: warning: converting 'false' to pointer type for argument 2 of 'jint* _JNIEnv::GetIntArrayElements(jintArray, jboolean*)' [-Wconversion-null] cbuf = env->GetIntArrayElements(buf, false); ^ [armeabi-v7a] Compile++ thumb: ProcessImg <= copyToAssets.cpp [armeabi-v7a] Compile++ thumb: ProcessImg <= detectFace.cpp [armeabi-v7a] SharedLibrary : libProcessImg.so /Users/yanzi/work/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: hidden symbol '__aeabi_atexit' in /Users/yanzi/work/android-ndk-r10d/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/thumb/libgnustl_static.a(atexit_arm.o) is referenced by DSO /Users/yanzi/work/OpenCV-android-sdk/sdk/native/jni/../libs/armeabi-v7a/libopencv_java.so [armeabi-v7a] Install : libProcessImg.so => libs/armeabi-v7a/libProcessImg.so
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) ifeq ("$(wildcard $(OPENCV_MK_PATH))","") #try to load OpenCV.mk from default install location #include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk include /Users/yanzi/work/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk else include $(OPENCV_MK_PATH) endif LOCAL_LDLIBS += -lm -llog LOCAL_MODULE := ProcessImg LOCAL_SRC_FILES := DetectFace_JNI.cpp \ src/copyToAssets.cpp \ src/detectFace.cpp include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) OpenCV_INSTALL_MODULES:=on OPENCV_CAMERA_MODULES:=off OPENCV_LIB_TYPE:=STATIC ifeq ("$(wildcard $(OPENCV_MK_PATH))","") #try to load OpenCV.mk from default install location #include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk include /Users/yanzi/work/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk else include $(OPENCV_MK_PATH) endif LOCAL_MODULE := ProcessImg LOCAL_SRC_FILES := DetectFace_JNI.cpp \ src/copyToAssets.cpp \ src/detectFace.cpp LOCAL_LDLIBS += -lm -llog include $(BUILD_SHARED_LIBRARY)
OpenCV_INSTALL_MODULES:=on
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=STATIC
這三句話,尤其是OPENCV_LIB_TYPE:=STATIC是要害,沒這一句編譯出來的so還是要依賴libopencv_java.so的。而且這句話必須放在include OpenCV.mk文件之前。切記切記!