0

I am trying to integrate openCV in Android studio for my latest project. I followed the following steps:

  1. Imported new module ..\OpenCV-android-sdk\java\
  2. Added dependancy OpenCVLibrary320
  3. Changed compilesdk and targetsdk versions to 23 and buildToolsVersion to 25.0.0 in the build.gradle of OpenCVLibrary320
  4. Copied the contents of ..\OpenCV-android-sdk\sdk\native to app\main\src\jniLibs (After creating a jni folder)
  5. Wrote a snippet of code to test if it was working

But I got the error:

Error:Execution failed for task ':app:compileDebugNdk'. Error: Your project contains C++ files but it is not using a supported native build system. Consider using CMake or ndk-build integration with the stable Android Gradle plugin: https://developer.android.com/studio/projects/add-native-code.html or use the experimental plugin: https://developer.android.com/studio/build/experimental-plugin.html.

How can I fix this problem?

Note: In step 4, I created the jniLibs folder but it did not show up in the 'Android' view so I had to copy the contents to the jniLibs folder in the 'Project' view.

user427913
  • 41
  • 5
  • https://stackoverflow.com/questions/43766092/reg-adding-opencv-to-native-c-code-through-cmake-on-android-studio/43886764#43886764 this is the by far best solution for integrating opencv in android – Thesoham24 Jul 05 '17 at 12:54
  • 2
    Possible duplicate of [Reg. Adding OpenCV to Native C code through CMake on Android Studio](https://stackoverflow.com/questions/43766092/reg-adding-opencv-to-native-c-code-through-cmake-on-android-studio) – Bob Swager Jul 05 '17 at 13:26

2 Answers2

0

In gradle add module dependency:

include ':libraries:opencv'

add in build.gradle with this content

apply plugin: 'android-library'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:2.3.2'

    }
}

android {
    compileSdkVersion 25
buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0.0"
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            aidl.srcDirs = ['src']
        }
    }
}
0

Manualy add the jar file in the lib folder,

app -> libs -> xyz.jar

This will also create duplicate jar issue, remove from the previous folder, because it gets compiled twice if you do not remove

Niraj Sanghani
  • 1,493
  • 15
  • 23