Home Can't import import android.hardware.camera2 classes
Reply: 4

Can't import import android.hardware.camera2 classes

Vicktory Calculus Man Omole
1#
Vicktory Calculus Man Omole Published in 2015-12-25 07:38:53Z

I imported the opencv android library to my android studio and the Camera2Renderer class has a lot of compiler errors because the android.hardware.camera2 classes can't be imported.

Vicktory Calculus Man Omole
2#
Vicktory Calculus Man Omole Reply to 2015-12-26 05:55:09Z

I solved the problem. Jim was right, i did not have the correct target API. For the next person who has this problem and finds this thread, the solution is that you have to make sure that the build.gradle files for your project and your openCV match. Thanks to everyone who helped me, and Merry Christmas!

J. Chomel
3#
J. Chomel Reply to 2017-03-08 10:30:34Z

i am working with openCVLibrary3.2.0 and trying to run its sample and faced same issue but i changed gradle files for both mysampleApp and openCVLibrary320 module as below

This is my app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "org.opencv.face"
        minSdkVersion 9
        targetSdkVersion 21
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_5
            targetCompatibility JavaVersion.VERSION_1_5
        }

        ndk {
            moduleName "native_sample"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
}

dependencies {
    compile project(path: ':openCVLibrary320')
}

and this my OpenCV library module build.gradle file

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 21
    }

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

Note: things to notice are that compileSdkVersion,buildToolsVersion,minSdkVersion, targetSdkVersion these must be same for all gradle files

i changed the compileSdkVersion from 14 to 23 and buildToolsVersion to "23.0.2" this solved the camera2 import related issue

ADyson
4#
ADyson Reply to 2017-10-31 11:03:59Z

I am working on openCVLibrary330 trying to run its sample and faced same issue but i changed gradle files for openCVLibrary330 module as below

This is my app build.gradle

apply plugin: 'com.android.library'

android {
  compileSdkVersion 23

  buildToolsVersion "26.0.2"

  defaultConfig {
    minSdkVersion 8
    targetSdkVersion 21
  }

  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
  }
}
Vishudh Sasidharan
5#
Vishudh Sasidharan Reply to 2018-01-02 13:21:24Z

I had the same problem. But, as many people have suggested I didn't had to change the gradle files to match exactly the same. I changed my compileSdkVersion and buildToolsVersion to the same on both gradle files, the rest are different. Its working fine now.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.462867 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO