gaurav_kumar
gaurav_kumar

Reputation: 41

Unable to import PreviewConfig class from package androidx.camera.core

I am trying to use camerax api for a camera application,but i am facing a problem. The class PreviewConfig is unable to resolve. This is my build.gradle(app) file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.cameraapi"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    // CameraX core library
    def camerax_version = "1.0.0-alpha09"
    implementation "androidx.camera:camera-core:${camerax_version}"
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    // If you want to use the CameraX View class
    implementation "androidx.camera:camera-view:1.0.0-alpha06"
    // If you want to use the CameraX Extensions library
    implementation "androidx.camera:camera-extensions:1.0.0-alpha06"
    // If you want to use the CameraX Lifecycle library
    implementation "androidx.camera:camera-lifecycle:1.0.0-alpha03"
}

MainActivity.class file is

package com.example.cameraapi;

import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.PreviewConfig; //this line is showing error
import android.os.Bundle;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

in the above code line,"import androidx.camera.core.PreviewConfig;" is not resolving.

Upvotes: 4

Views: 6977

Answers (3)

Sergei Maleev
Sergei Maleev

Reputation: 327

Instead

// Create configuration object for the viewfinder use case
val previewConfig = PreviewConfig.Builder().apply {
    setTargetResolution(Size(640, 480))
}.build()


// Build the viewfinder use case
val preview = Preview(previewConfig)

use

   // Build the viewfinder use case
    val preview = Preview.Builder()
        .setTargetResolution(Size(640, 480))
        .build()

Upvotes: 5

Husayn Hakeem
Husayn Hakeem

Reputation: 4570

With the recent camerax versions (I think starting from alpha06 or alpha07), PreviewConfig is no longer needed to build a Preview use case (this also applies to the other use cases, ImageAnalysis and ImageCapture). You can now build a Preview instance using its Builder class.

Preview preview = new Preview.Builder().build();

You could of course configure it as you wish using the Builder's methods (to set the target resolution for instance).

Upvotes: 8

qki
qki

Reputation: 1929

Unfortunately they deprecated it, you should look at the changes. From what I know instead of import androidx.camera.core.PreviewConfig; you should use import androidx.camera.core.impl.PreviewConfig

Upvotes: 0

Related Questions