1

I want to use OpenCV4Android in Android Studio. I downloaded OpenCV for Android from this link: http://opencv.org/downloads.html

But, when I try to import it, I get different errors in Camera2Renderer.java like, Cannot resolve symbol 'camera2', Cannot resolve symbol 'CameraDevice', Cannot resolve symbol 'Size', and Cannot resolve symbol 'CaptureRequest'.

I have tried both methods available here:

OpenCV in Android Studio

http://answers.opencv.org/question/14546/how-to-work-with-opencv4android-in-android-studio/

But, I get the same error.

Can anyone please tell me how to solve this error to be able to use openCV?

Thank you.

Community
  • 1
  • 1
Dania
  • 1,478
  • 2
  • 22
  • 51

1 Answers1

3

I faced the same issue while configuring OpenCV SDK with Android Studio.

I am using the latest SDK build of OpenCV : OpenCV-3.1.0-android-sdk

Please ensure that you have configured your build.gradle scripts.

Build.gradle(Module: app) -->

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
    applicationId "com.example.dev.opencvapp"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
  }
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLib/'] } }
}

 dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')
  testCompile 'junit:junit:4.12'
  compile 'com.android.support:appcompat-v7:24.2.1'
  compile project(':openCVLibrary310')
  }

Build.gradle(Module: openCVLibrary310) -->

apply plugin: 'com.android.library'

android {
  compileSdkVersion 24
  buildToolsVersion "19.1.0"

  defaultConfig {
    minSdkVersion 8
    targetSdkVersion 21
  }

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
      }
  }
}

After doing this you should be able to build the app with out any errors.

I hope I helped you!!

Benedict
  • 448
  • 2
  • 13