Android Studio, OpenCV, C++, jni, NDK - unable to

2019-05-28 15:06发布

问题:

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

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:

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:

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

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:

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?