随着arm 新一代核心不断升级,目前大多数Android平台均可运行64bit了,故项目需要在原来的32bit基础上重新编译了opencv适用于Android Native层运行的64bit版本(和Android OS 自带的opencv相互独立)。
打包运行和发布发现这个名字很显眼。使用不当就有冲突可能。一个办法改名,于是恶补cmake。尝试多种改法,不济于是,得益于老大Sam的优秀思路,问题完美解决。
一、本项目环境:
Linux 64bit OS/ NDK-r14b/camke-2.8.12 / OpenCV-3.1/JDK-1.8/ Ant-1.10.1
二 、可行改法如下:
1.OpenCV3.1/opencv/platforms/build_android_arm/$ make BERBOSE=1
记录所有日志。找到生成*.so的编译语句。
cd /home/hanpeng/workspace/OpenCV-3.1/opencv/platforms/build_android_arm/modules/java && /usr/bin/cmake -E cmake_link_script CMakeFiles/opencv_java.dir/link.txt --verbose=1
/home/hanpeng/android/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc -fPIC -fexceptions -frtti -Wno-psabi --sysroot=/home/hanpeng/android/android-ndk-r14b/platforms/android-22/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -fomit-frame-pointer -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300 -O3 -DNDEBUG -DNDEBUG -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libopencv_java3.so -o ../../lib/arm64-v8a/libopencv_java3.so CMakeFiles/opencv_java.dir/generator/src/cpp/Mat.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/converters.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/jni_part.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/utils.cpp.o CMakeFiles/opencv_java.dir/__/core/misc/java/src/cpp/core_manual.cpp.o CMakeFiles/opencv_java.dir/__/features2d/misc/java/src/cpp/features2d_converters.cpp.o CMakeFiles/opencv_java.dir/core.cpp.o CMakeFiles/opencv_java.dir/imgproc.cpp.o CMakeFiles/opencv_java.dir/ml.cpp.o CMakeFiles/opencv_java.dir/photo.cpp.o CMakeFiles/opencv_java.dir/video.cpp.o CMakeFiles/opencv_java.dir/imgcodecs.cpp.o CMakeFiles/opencv_java.dir/videoio.cpp.o CMakeFiles/opencv_java.dir/objdetect.cpp.o CMakeFiles/opencv_java.dir/features2d.cpp.o CMakeFiles/opencv_java.dir/calib3d.cpp.o -L/home/hanpeng/workspace/OpenCV-3.1/opencv/platforms/build_android_arm/install/libs/arm64-v8a -Wl,-whole-archive ../../lib/arm64-v8a/libopencv_core.a ../../lib/arm64-v8a/libopencv_flann.a ../../lib/arm64-v8a/libopencv_imgproc.a ../../lib/arm64-v8a/libopencv_ml.a ../../lib/arm64-v8a/libopencv_photo.a ../../lib/arm64-v8a/libopencv_video.a ../../lib/arm64-v8a/libopencv_imgcodecs.a ../../lib/arm64-v8a/libopencv_videoio.a ../../lib/arm64-v8a/libopencv_highgui.a ../../lib/arm64-v8a/libopencv_objdetect.a ../../lib/arm64-v8a/libopencv_features2d.a ../../lib/arm64-v8a/libopencv_calib3d.a ../../lib/arm64-v8a/libopencv_shape.a ../../lib/arm64-v8a/libopencv_superres.a ../../lib/arm64-v8a/libopencv_stitching.a ../../lib/arm64-v8a/libopencv_videostab.a -Wl,-no-whole-archive -ldl -lm -llog ../../3rdparty/lib/arm64-v8a/libtbb.a -ljnigraphics ../../lib/arm64-v8a/libopencv_objdetect.a ../../lib/arm64-v8a/libopencv_photo.a ../../lib/arm64-v8a/libopencv_video.a ../../lib/arm64-v8a/libopencv_calib3d.a ../../lib/arm64-v8a/libopencv_features2d.a ../../lib/arm64-v8a/libopencv_flann.a ../../lib/arm64-v8a/libopencv_ml.a ../../lib/arm64-v8a/libopencv_highgui.a ../../lib/arm64-v8a/libopencv_videoio.a ../../lib/arm64-v8a/libopencv_imgcodecs.a ../../lib/arm64-v8a/libopencv_imgproc.a ../../lib/arm64-v8a/libopencv_core.a ../../3rdparty/lib/arm64-v8a/liblibjpeg.a ../../3rdparty/lib/arm64-v8a/liblibwebp.a ../../3rdparty/lib/arm64-v8a/liblibpng.a ../../3rdparty/lib/arm64-v8a/liblibtiff.a ../../3rdparty/lib/arm64-v8a/liblibjasper.a ../../3rdparty/lib/arm64-v8a/libIlmImf.a -lz -llog ../../3rdparty/lib/arm64-v8a/libtbb.a -lc -ldl -lm "/home/hanpeng/android/android-ndk-r14b/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a" "/home/hanpeng/android/android-ndk-r14b/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libsupc++.a" -lm
cd /home/hanpeng/workspace/OpenCV-3.1/opencv/platforms/build_android_arm/modules/java && /home/hanpeng/android/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip --strip-unneeded /home/hanpeng/workspace/OpenCV-3.1/opencv/platforms/build_android_arm/lib/arm64-v8a/libopencv_java3.so
简单改名字不能运行的原因:参数-soname
2.修改编译对应*.so的语句。
3.OpenCV3.1/opencv/platforms/build_android_arm/modules/java$ 执行以下命令:
/home/hanpeng/android/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc -fPIC -fexceptions -frtti -Wno-psabi --sysroot=/home/hanpeng/android/android-ndk-r14b/platforms/android-22/arch-arm64 -funwind-tables -fsigned-char -no-canonical-prefixes -fdata-sections -ffunction-sections -Wa,--noexecstack -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -fvisibility-inlines-hidden -fstrict-aliasing -funswitch-loops -finline-limit=300 -O3 -DNDEBUG -DNDEBUG -Wl,--no-undefined -Wl,-allow-shlib-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -o ../../lib/arm64-v8a/libopencv_java3.so CMakeFiles/opencv_java.dir/generator/src/cpp/Mat.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/converters.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/jni_part.cpp.o CMakeFiles/opencv_java.dir/generator/src/cpp/utils.cpp.o CMakeFiles/opencv_java.dir/__/core/misc/java/src/cpp/core_manual.cpp.o CMakeFiles/opencv_java.dir/__/features2d/misc/java/src/cpp/features2d_converters.cpp.o CMakeFiles/opencv_java.dir/core.cpp.o CMakeFiles/opencv_java.dir/imgproc.cpp.o CMakeFiles/opencv_java.dir/ml.cpp.o CMakeFiles/opencv_java.dir/photo.cpp.o CMakeFiles/opencv_java.dir/video.cpp.o CMakeFiles/opencv_java.dir/imgcodecs.cpp.o CMakeFiles/opencv_java.dir/videoio.cpp.o CMakeFiles/opencv_java.dir/objdetect.cpp.o CMakeFiles/opencv_java.dir/features2d.cpp.o CMakeFiles/opencv_java.dir/calib3d.cpp.o -L/home/hanpeng/workspace/OpenCV-3.1/opencv/platforms/build_android_arm/install/libs/arm64-v8a -Wl,-whole-archive ../../lib/arm64-v8a/libopencv_core.a ../../lib/arm64-v8a/libopencv_flann.a ../../lib/arm64-v8a/libopencv_imgproc.a ../../lib/arm64-v8a/libopencv_ml.a ../../lib/arm64-v8a/libopencv_photo.a ../../lib/arm64-v8a/libopencv_video.a ../../lib/arm64-v8a/libopencv_imgcodecs.a ../../lib/arm64-v8a/libopencv_videoio.a ../../lib/arm64-v8a/libopencv_highgui.a ../../lib/arm64-v8a/libopencv_objdetect.a ../../lib/arm64-v8a/libopencv_features2d.a ../../lib/arm64-v8a/libopencv_calib3d.a ../../lib/arm64-v8a/libopencv_shape.a ../../lib/arm64-v8a/libopencv_superres.a ../../lib/arm64-v8a/libopencv_stitching.a ../../lib/arm64-v8a/libopencv_videostab.a -Wl,-no-whole-archive -ldl -lm -llog ../../3rdparty/lib/arm64-v8a/libtbb.a -ljnigraphics ../../lib/arm64-v8a/libopencv_objdetect.a ../../lib/arm64-v8a/libopencv_photo.a ../../lib/arm64-v8a/libopencv_video.a ../../lib/arm64-v8a/libopencv_calib3d.a ../../lib/arm64-v8a/libopencv_features2d.a ../../lib/arm64-v8a/libopencv_flann.a ../../lib/arm64-v8a/libopencv_ml.a ../../lib/arm64-v8a/libopencv_highgui.a ../../lib/arm64-v8a/libopencv_videoio.a ../../lib/arm64-v8a/libopencv_imgcodecs.a ../../lib/arm64-v8a/libopencv_imgproc.a ../../lib/arm64-v8a/libopencv_core.a ../../3rdparty/lib/arm64-v8a/liblibjpeg.a ../../3rdparty/lib/arm64-v8a/liblibwebp.a ../../3rdparty/lib/arm64-v8a/liblibpng.a ../../3rdparty/lib/arm64-v8a/liblibtiff.a ../../3rdparty/lib/arm64-v8a/liblibjasper.a ../../3rdparty/lib/arm64-v8a/libIlmImf.a -lz -llog ../../3rdparty/lib/arm64-v8a/libtbb.a -lc -ldl -lm "/home/hanpeng/android/android-ndk-r14b/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a" "/home/hanpeng/android/android-ndk-r14b/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libsupc++.a" -lm
这样执行完库大小是原来的1.5倍左右。
4.执行如下命令:解决库大小问题
/home/hanpeng/android/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip --strip-unneeded /home/hanpeng/workspace/OpenCV-3.1/opencv/platforms/build_android_arm/lib/arm64-v8a/libopencv_java3.so
至此这个so库就改完了。