Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 300
gaurav_kumar Avatar asked Sep 02 '25 14:09

gaurav_kumar


1 Answers

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).

like image 108
Husayn Hakeem Avatar answered Sep 05 '25 03:09

Husayn Hakeem