Ask Your Question
0

unable to use libopencv_java4.so in android studio with c++

asked 2018-12-14 03:35:28 -0500

zidek gravatar image

updated 2018-12-14 05:28:20 -0500

After compilation it is problem to use new opencv 4.0 library in Android studio with c++ (clang++.exe android studio 3.4 canary and 3.2 tested), used new library libopencv_java4.so (same problem with x86_64, arm7, arm8)

send errors during compilation in android studio project:

error: undefined reference to 'cv::dnn::dnn4_v20181205::NMSBoxes(std:
error: undefined reference to 'cv::CommandLineParser::CommandLineParser(int, cha
opencv2/core/utility.hpp:897: error: undefined reference to 'cv::CommandLineParser::getByName(std::__ndk1::ba
opencv2/core/utility.hpp:897: error: undefined reference to 'cv::CommandLineParser::getByName(std::__

what is wrong dev version not working for android? missing compiled version for android i must compile my own library....

Full error list from android studio: Executing tasks: [clean, :app:assembleRelease]

Task :clean UP-TO-DATE

Task :app:externalNativeBuildCleanDebug Clean opencv2unity armeabi-v7a,test-lib armeabi-v7a Cleaning... 0 files. Clean test-lib arm64-v8a,opencv2unity arm64-v8a Cleaning... 0 files. Clean test-lib x86,opencv2unity x86 Cleaning... 0 files. Clean opencv2unity x86_64,test-lib x86_64 Cleaning... 0 files.

Task :app:externalNativeBuildCleanRelease Clean opencv2unity armeabi-v7a,test-lib armeabi-v7a Cleaning... 0 files. Clean test-lib arm64-v8a,opencv2unity arm64-v8a Cleaning... 0 files. Clean test-lib x86,opencv2unity x86 Cleaning... 0 files. Clean opencv2unity x86_64,test-lib x86_64 Cleaning... 0 files.

Task :app:clean Task :app:preBuild UP-TO-DATE Task :app:preReleaseBuild UP-TO-DATE Task :app:compileReleaseAidl NO-SOURCE Task :app:compileReleaseRenderscript Task :app:checkReleaseManifest Task :app:generateReleaseBuildConfig Task :app:generateReleaseResValues Task :app:generateReleaseResources Task :app:packageReleaseResources Task :app:processReleaseManifest Task :app:generateReleaseRFile Task :app:prepareLintJar UP-TO-DATE Task :app:generateReleaseSources Task :app:javaPreCompileRelease Task :app:compileReleaseJavaWithJavac Task :app:extractReleaseAnnotations Task :app:mergeReleaseConsumerProguardFiles UP-TO-DATE Task :app:mergeReleaseShaders Task :app:compileReleaseShaders Task :app:generateReleaseAssets Task :app:packageReleaseAssets Task :app:packageReleaseRenderscript NO-SOURCE Task :app:processReleaseJavaRes NO-SOURCE Task :app:transformResourcesWithMergeJavaResForRelease Task :app:transformClassesAndResourcesWithSyncLibJarsForRelease Task :app:generateJsonModelRelease UP-TO-DATE

Task :app:externalNativeBuildRelease Build opencv2unity x86_64 [1/2] Building CXX object ../../../cxx/release/x86_64/CMakeFiles/opencv2uni ty.dir/src/main/cpp/opencv2unity.cpp.o In file included from D:\androidprojects\SimpleNativeLibrary\app\src\main\cpp\opencv2unity.cpp:39: D:\androidprojects\SimpleNativeLibrary\app\src\main\cpp/common.h:76:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ 1 warning generated. [2/2] Linking CXX shared library D:\a ndroidprojects\SimpleNativeLibrary\app\build\intermediates\cmake\release\obj\x86_64\libopencv2unity.so FAILED: cmd.exe /C "cd . && D:\androidsdk_cannary\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=x86_64-none-linux-android21 --gcc-toolchain=D:/androidsdk_cannary/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 -fPIC --sysroot D:/androidsdk_cannary/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -O2 -DNDEBUG -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libopencv2unity.so -o D:\androidprojects\SimpleNativeLibrary\app\build\intermediates\cmake\release\obj\x86_64\libopencv2unity.so ../../../cxx/release/x86_64/CMakeFiles/opencv2unity.dir/src/main/cpp/opencv2unity.cpp.o D:/androidprojects/SimpleNativeLibrary/app/src/main/jniLibs/x86_64/libopencv_java4.so -llog -latomic -lm && cd ." D:\androidprojects\SimpleNativeLibrary\app\src\main\cpp ...

(more)
edit retag flag offensive close merge delete

Comments

your error messages are incomplete. can you take another look ?

also, which compiler / stdc++ lib was used for your app (and also for the libs) ?

berak gravatar imageberak ( 2018-12-14 04:24:16 -0500 )edit

i'm no android user,, but those errors look like your app expects to find functions using std::__ndk1 (which is stdc++, right ?) while the opencv libs were built with something else (maybe gnustl ? idk.) and a different compiler

berak gravatar imageberak ( 2018-12-14 05:28:50 -0500 )edit

did you build the opencv android libs locally ?

berak gravatar imageberak ( 2018-12-14 05:32:33 -0500 )edit

android library was compiled with mingw according tutorial and compiled ok for all platforms x86_64 arm7 arm8 without any problem

zidek gravatar imagezidek ( 2018-12-14 05:39:16 -0500 )edit

again, i think, it's a compiler / stl mismatch. e.g. gcc / gnustl is used for the prebuilt packs:

https://pullrequest.opencv.org/buildb...

(but sorry, i don't have any answer)

berak gravatar imageberak ( 2018-12-14 05:43:03 -0500 )edit

cmake toolchain have default compiler STL set to gnustl_static (GCC) and Android studio have c++_static (CLANG), but it is not possible compile library with c++_static because no support of clang compiler in NDK 18 ar NDK 19, ANY SUGGESTION TO COMPILE LIBOPENCV_JAVA4.SO with CLANG comiler????? in cmake change to c++_static => error in tiff openexr protobuff.....

zidek gravatar imagezidek ( 2018-12-15 01:36:47 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-12-15 16:07:04 -0500

zidek gravatar image

updated 2018-12-15 16:08:01 -0500

problem solved libopencv_java4.so must be compiled with c++_static and clang++ (select cmake.toolchain file from ndk17 folder not from opencv folder platform

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-12-14 03:35:28 -0500

Seen: 325 times

Last updated: Dec 14 '18