您的位置:首页 > 移动开发 > Android开发

Android JNI 编译正确 但是提示程序有错误无法运行 而且还看不到任何错误提示 的解决方法

2013-09-11 14:33 417 查看
前几篇中一直在通过Android做JNI调用,关于JNI的配置请见:http://blog.csdn.net/watkinsong/article/details/9849973

但是前一段时间就遇到了整个工程编译都没有问题,但是没有办法运行的问题,编译结果提示如下:

Your Project contains error(s), please fix them before running your application.

但是,整个工程的编译是没有问题的。

查了很多资料,网上大部分都说是证书过期,但是貌似我这里不适用,也按照网上说的做了,没效果,而且证书过期需要一年的时间,我才搞android不到两个星期。



14:15:00 **** Auto Build of configuration Default for project IBMFaceDetectDemo ****
"D:\\WeiSONG\\sdk\\Android\\android-ndk-r9\\ndk-build.cmd" -j2
Android NDK: WARNING: APP_PLATFORM android-18 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
"Compile++ thumb : Canny <= Canny.cpp
"Compile++ thumb : Canny <= Canny.cpp
Install : libnative_camera_r2.2.0.so => libs/armeabi-v7a/libnative_camera_r2.2.0.so
Install : libnative_camera_r2.3.3.so => libs/armeabi-v7a/libnative_camera_r2.3.3.so
Install : libnative_camera_r3.0.1.so => libs/armeabi-v7a/libnative_camera_r3.0.1.so
Install : libnative_camera_r4.0.0.so => libs/armeabi-v7a/libnative_camera_r4.0.0.so
Install : libnative_camera_r4.0.3.so => libs/armeabi-v7a/libnative_camera_r4.0.3.so
SharedLibrary : libCanny.so
Install : libnative_camera_r2.2.0.so => libs/armeabi/libnative_camera_r2.2.0.so
Install : libnative_camera_r3.0.1.so => libs/armeabi/libnative_camera_r3.0.1.so
Install : libnative_camera_r2.3.3.so => libs/armeabi/libnative_camera_r2.3.3.so
Install : libnative_camera_r4.0.0.so => libs/armeabi/libnative_camera_r4.0.0.so
Install : libnative_camera_r4.0.3.so => libs/armeabi/libnative_camera_r4.0.3.so
SharedLibrary : libCanny.so
Install : libCanny.so => libs/armeabi/libCanny.so
Install : libCanny.so => libs/armeabi-v7a/libCanny.so

14:15:03 Build Finished (took 2s.670ms)


可以看到,整个程序编译完全正常,而且整个项目没有任何错误提示,红叉啊什么的



上图中可以看到整个项目没有任何错误提示。

那么?项目的问题在哪里呢?仔细看看编译的过程中,闪过了一些红的错误提示,但是由于安装了ADT的原因,这个时候的输出都是编译的信息,需要切换到Eclipse系统的输出看看错误,我就是因为才接触Eclipse不知道中间还输出了其他的错误信息

切换到Eclipse的控制台输出,会看到下面的错误提示:

[2013-09-11 14:09:54 - IBMFaceDetectDemo] Error generating final archive: Found duplicate file for APK: lib/armeabi/libnative_camera_r2.2.0.so
Origin 1: D:\workspace\IBMFaceDetectDemo\libs\armeabi\libnative_camera_r2.2.0.so
Origin 2: D:\WeiSONG\sdk\opencv2.4android\OpenCV-2.4.0\libs\armeabi\libnative_camera_r2.2.0.so
[2013-09-11 14:15:50 - IBMFaceDetectDemo] Error generating final archive: Found duplicate file for APK: lib/armeabi/libnative_camera_r2.2.0.so
Origin 1: D:\workspace\IBMFaceDetectDemo\libs\armeabi\libnative_camera_r2.2.0.so
Origin 2: D:\WeiSONG\sdk\opencv2.4android\OpenCV-2.4.0\libs\armeabi\libnative_camera_r2.2.0.so

这里提示了动态链接库重复了,再仔细看看我们的工程目录:



NDK 在编译的时候根据Opencv.mk的参数设置,讲那几个关于摄像头的动态链接库复制到libs文件夹里面了,然后我们的工程还引用了Opencv2.4的这个lib库,所以造成了本工程的lib和opencv2.4的外部lib冲突了。

看一下我们原来的Android.mk文件:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

OPENCV_LIB_TYPE:=STATIC
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
#try to load OpenCV.mk from default install location
include D:/WeiSONG/sdk/opencv2.4android/OpenCV-2.4.0/share/OpenCV/OpenCV.mk
else
include $(OPENCV_MK_PATH)
endif
LOCAL_MODULE := Canny
LOCAL_SRC_FILES := Canny.cpp
include $(BUILD_SHARED_LIBRARY)

这个mk文件中,没有定义 下面这句话,所以会导致opencv.mk在编译文件的时候讲动态链接库复制了
OPENCV_CAMERA_MODULES:=off

看一下opencv.mk的内容(部分):
ifeq (${OPENCV_CAMERA_MODULES},off)
OPENCV_CAMERA_MODULES:=
else
ifeq ($(TARGET_ARCH_ABI),armeabi)
OPENCV_CAMERA_MODULES:= native_camera_r2.2.0 native_camera_r2.3.3 native_camera_r3.0.1 native_camera_r4.0.0 native_camera_r4.0.3
endif
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
OPENCV_CAMERA_MODULES:= native_camera_r2.2.0 native_camera_r2.3.3 native_camera_r3.0.1 native_camera_r4.0.0 native_camera_r4.0.3
endif
ifeq ($(TARGET_ARCH_ABI),x86)
OPENCV_CAMERA_MODULES:= native_camera_r2.3.3 native_camera_r3.0.1 native_camera_r4.0.3
endif
endif

可以看到如果不定义OPENCV_CAMERA_MODULES
这个变量的话,会自动复制一些摄像头相关的链接库。

所以在我们的工程的Android.mk中,应该添加上

OPENCV_CAMERA_MODULES:=off这一句,然后就可以正常的运行你的程序了,在libs文件夹中也不会看到摄像头相关的链接库了。

新的Android.mk代码:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=off
OPENCV_LIB_TYPE:=STATIC
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
#try to load OpenCV.mk from default install location
include D:/WeiSONG/sdk/opencv2.4android/OpenCV-2.4.0/share/OpenCV/OpenCV.mk
else
include $(OPENCV_MK_PATH)
endif
LOCAL_MODULE := Canny
LOCAL_SRC_FILES := Canny.cpp
include $(BUILD_SHARED_LIBRARY)

然后在编译信息提示中,也不会看到像原来的提示信心那么多了:
14:30:41 **** Auto Build of configuration Default for project IBMFaceDetectDemo ****
"D:\\WeiSONG\\sdk\\Android\\android-ndk-r9\\ndk-build.cmd" -j2
Android NDK: WARNING: APP_PLATFORM android-18 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
"Compile++ thumb : Canny <= Canny.cpp
"Compile++ thumb : Canny <= Canny.cpp
SharedLibrary : libCanny.so
SharedLibrary : libCanny.so
Install : libCanny.so => libs/armeabi-v7a/libCanny.so
Install : libCanny.so => libs/armeabi/libCanny.so

14:30:43 Build Finished (took 2s.195ms)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐