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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With