Saturday, July 23, 2016

How to Compile Mixed Processing OpenCV Tutorial App on Android Studio

The second OpenCV for Android tutorial app, namely Mixed Processing, differs from Camera Preview app in that it also has a C++ source file, thus requiring Android NDK. To compile this project in Android Studio, the first several steps are identical to Camera Preview app, so follow instructions in my previous post. In summary, these steps that are required to integrate OpenCV for Android SDK statically are:

Even after all the above changes, the project will still not compile because it contains native C++ file, which we must let Android Studio know what to do with. So, here we go again! I will assume the project directory of ~/AndroidStudioProjects/tutorial-2-mixedprocessing. Before we do anything further, make sure to install Android NDK from SDK Manager.

When you try to compile the project, it will complain with the following error message:Error:(12, 0) NDK integration is deprecated in the current plugin.Consider trying the new experimental pluginSet "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration

Let's do what it asks for. You probably do not have this gradle.properties file yet, so let's create it.$ echo "android.useDeprecatedNdk=true" > ~/AndroidStudioProjects/tutorial-2-mixedprocessing/gradle.properties

When you try to build the project, it will now complain with two errors:Error:(2, 33) opencv2/core/core.hpp: No such file or directory...Error:Execution failed for task ':openCVTutorial2MixedProcessing:compileDebugNdk'.> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '~/Library/Android/Sdk/ndk-bundle/ndk-build'' finished with non-zero exit value 2