Can't import import android.hardware.camera2 classes

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.

enter image description here

  • Android Unit Testing: Bundle/Parcelable
  • Why is touchstart event after click?
  • Intent to start a navigation activity
  • What's Adapter.getItem() for?
  • Create a custom Drawable and use it in XML
  • How to create multiple Android apps from one code base
  • Use ActiveAndroid on existing database-content
  • Text does not ellipsize
  • Hide/Show Action Bar Option Menu Item for different fragments
  • Android: TextView automatically truncate and replace last 3 char of String
  • What font file types does Android support?
  • How to keep soft keyboard from opening on activity launch in Android?
  • 2 Solutions collect form web for “Can't import import android.hardware.camera2 classes”

    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!

    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

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.