首页 > 解决方案 > 未解决的参考:requireLensFacing | 安卓工作室

问题描述

我收到“未解决的参考:requireLensFacing”CameraSelector.Builder.requireLensFacing(lensFacing).build()

我添加了相机核心依赖项,实际上我可以打开 CameraSelector 类并在其中找到“requireLensFacing”方法。但我就是不能用。

这是我的应用程序等级:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-android-extensions'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.devtyagi.facemaskdetector"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures{
        mlModelBinding true
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

    implementation 'com.google.android.material:material:1.2.1'
    implementation "androidx.camera:camera-core:${camerax_version}"
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    implementation "androidx.camera:camera-lifecycle:${camerax_version}"
    implementation "androidx.camera:camera-view:1.0.0-alpha20"
    implementation "androidx.camera:camera-extensions:1.0.0-alpha20"
    implementation "org.tensorflow:tensorflow-lite-metadata:${tflite}"
    implementation "org.tensorflow:tensorflow-lite-gpu:2.2.0"
    implementation 'org.tensorflow:tensorflow-lite-support:0.1.0-rc1'

    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

这是我的项目级 gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.21"
    ext.tflite = "0.1.0-rc1"
    ext.camerax_version = "1.0.0-rc01"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是错误:

截屏

我该如何解决这个问题?谢谢你

标签: androidandroid-studiokotlingradleandroid-camerax

解决方案


你应该像这样使用它,
val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()
你正在使用Builder替换它Builder()


推荐阅读