2

I'm attempting to get OpenCV C++ calls to work within Android Studio using jni & the Android Studio NDK. These are the references I've been working from:

https://github.com/opencv/opencv/tree/master/samples/android/tutorial-2-mixedprocessing

https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#0

http://hujiaweibujidao.github.io/blog/2014/10/22/android-ndk-and-opencv-development-with-android-studio/

https://blog.nishtahir.com/2015/11/11/setting-up-for-android-ndk-development/

http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/

https://www.youtube.com/watch?v=G0vL7-_xuDM

https://www.youtube.com/watch?v=RmPuwdxR1qs

Android NDK: how to let gcc to use additional include directories

For the most part I've been attempting to get the 2nd OpenCV sample (first of the links above) to run within Android Studio. This is the closest I have gotten so far:

https://github.com/MicrocontrollersAndMore/OpenCVTestNative/tree/22895c5304c5fb7f0bd62c0f5eef494d3f0280f9

Currently I'm getting the error:

C:\Users\Chris.Dahms\Documents\AndroidOpenCVCppProgs\OpenCVTestNative\app\src\main\jni\jni_part.cpp
Error:(2, 28) opencv2/core.hpp: No such file or directory

I've tried everything in the above links to no avail.

I should mention that I can get the Java OpenCV calls to work within Android Studio, essentially following this post:

OpenCV in Android Studio

But no matter what I have done I have not been able to get the C++ jni calls to work. I made the above-linked GitHub project by starting with the project wizard, then adding parts from the 2nd OpenCV for Android sample:

https://github.com/opencv/opencv/tree/master/samples/android/tutorial-2-mixedprocessing

The other way I've tried it is downloading the OpenCV source from:

https://github.com/opencv/opencv

Then unzipping and using the Android Studio "Import Project (Eclipse ADT, Gradle, etc.)" Option. After import I get the message

enter image description here

I've read up on the experimental plugin and that does not seem to be the recommended way to go, so I choose the

Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration

Option, which puts the line:

android.useDeprecatedNdk=true

At the end of gradle.properties. After that I get many errors, however if I follow the steps from

OpenCV in Android Studio

again, that gets me back to the same

Error:(2, 28) opencv2/core.hpp: No such file or directory

here is what my screen looks like:

enter image description here

Here is the project if it would be helpful to look at the source:

https://github.com/MicrocontrollersAndMore/tutorial-2-mixedprocessing

Has anybody actually gotten this to work? I've seen some posts implying it's possible but I can't find any concrete instructions. Can anybody who has had some success with this please share with the rest of us ??

Edit: It has been suggested that this is an answer:

Android Studio with opencv for android ndk, opencv header files not found

While this did get me past the opencv2/core.hpp: No such file or directory error, in Android Studio the FindFeatures call still appears red as though the Java file can't see the C++ file:

enter image description here

And in the app's build.gradle file, multiple lines have underline errors:

enter image description here

enter image description here

Any further suggestions??

Further edit:

I forgot to mention that I get the underline errors in build.gradle with the additions outside the default bracket as well:

enter image description here

And when I run the app it crashes with the error

couldn't find "libmixed_sample.so"

in LogCat and on the phone gives the "unfortunately the app has stopped" error

Any further suggestions?

Community
  • 1
  • 1
cdahms
  • 3,402
  • 10
  • 49
  • 75
  • contents of Android.mk file would be helpful as the problem related to c++ code is not able to figure out where core.hpp present – hariprasad Jul 17 '16 at 06:31
  • Here is the first of the two from my attempts linked above: https://github.com/MicrocontrollersAndMore/OpenCVTestNative/blob/master/jni/Android.mk and here is the 2nd of the two: https://github.com/MicrocontrollersAndMore/tutorial-2-mixedprocessing/blob/master/app/src/main/jni/Android.mk I should mention that I've tried putting the jni directory at the (root of the project), (root of the project)/app, and (root of the project)/app/src/main, same error show above in all cases – cdahms Jul 17 '16 at 13:12
  • Possible duplicate of [Android Studio with opencv for android ndk, opencv header files not found](http://stackoverflow.com/questions/29214015/android-studio-with-opencv-for-android-ndk-opencv-header-files-not-found) – Francesca Nannizzi Jul 18 '16 at 12:35
  • Nicely defined set of attempts. Any progress? – Dale Aug 16 '16 at 14:18
  • No, and unfortunately it looks like this is a known issue within the OpenCV organization that may not be resolved for some time, check out this post: https://github.com/opencv/opencv/issues/5003 When I get back to this I'm going to give the Java function calls a thorough try. Since they wrap the OpenCV libs, which are true compiles, I'm hoping the performance loss will be negligible if any at all. – cdahms Aug 19 '16 at 00:06
  • @cdahms Did it work for you? I am asking the same question [here](https://stackoverflow.com/questions/44551292) – vyi Jun 14 '17 at 19:05

0 Answers0