繁体   English   中英

无法在 android 开发中使用 ML Kit

[英]Can't use the ML Kit in android development

我正在尝试在我的 Kotlin + Firebase 应用程序中实施人脸检测。 我遵循了 ML 站点中提供的 ML Kit 教程,但我不断收到与以下实施相关的错误:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/TelemetryLoggingOptions;
    at com.google.android.gms.internal.mlkit_vision_face.zzli.<init>(com.google.android.gms:play-services-mlkit-face-detection@@16.1.5:2)
    at com.google.android.gms.internal.mlkit_vision_face.zzli.zza(com.google.android.gms:play-services-mlkit-face-detection@@16.1.5:1)
    at com.google.mlkit.vision.face.internal.zzh.<init>(com.google.android.gms:play-services-mlkit-face-detection@@16.1.5:4)
    at com.google.mlkit.vision.face.internal.zze.create(com.google.android.gms:play-services-mlkit-face-detection@@16.1.5:9)
    at com.google.mlkit.common.sdkinternal.LazyInstanceMap.get(com.google.mlkit:common@@17.1.1:3)
    at com.google.mlkit.vision.face.internal.zzd.zzb(com.google.android.gms:play-services-mlkit-face-detection@@16.1.5:2)
    at com.google.mlkit.vision.face.FaceDetection.getClient(com.google.android.gms:play-services-mlkit-face-detection@@16.1.5:3)

我尝试使用两种方式

实施 'com.google.mlkit:face-detection:16.0.6'

实现 'com.google.android.gms:play-services-mlkit-face-detection:16.1.5'并在清单中添加元数据:

<meta-data
          android:name="com.google.mlkit.vision.DEPENDENCIES"
          android:value="face" />

在这两种方式中,我都会遇到同样的错误。 有谁知道如何解决它?

这是 gradle:

apply plugin: "com.android.dynamic-feature"
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply from: '../version_control.gradle'

android {

    buildFeatures {
        viewBinding true
    }

    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

    packagingOptions {
        exclude 'META-INF/library_release.kotlin_module'
    }

    sourceSets {
        main {
            /* https://wiki.vectorlabs.cloud/x/1IgVAg */
            res.srcDirs = [
                    'src/main/res/home',
                    'src/main/res/qrcode',
                    'src/main/res/gamification',
                    'src/main/res/cafDetails',
                    'src/main/res/registration.hub',
                    'src/main/res/registration.email',
                    'src/main/res/registration.vehicle',
                    'src/main/res/deliveryFlow',
            ]
        }
    }

}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation project(":base")
    api project(":delivery_types") /*Para usar a activity de Informacoes*/
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.googlecode.libphonenumber:libphonenumber:8.8.3'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    kapt 'com.github.bumptech.glide:glide:4.11.0'
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
    implementation 'com.github.qoqa:glide-svg:2.0.4'

    androidTestImplementation 'androidx.annotation:annotation:1.1.0'
    androidTestImplementation project(':base')

    // FirebaseUI for Firebase Realtime Database
    implementation 'com.firebaseui:firebase-ui-firestore:7.0.0'

    //SMS Retrieval API
    implementation 'com.google.android.gms:play-services-auth:19.0.0'
    implementation 'org.apache.commons:commons-lang3:3.11'
    implementation 'org.greenrobot:eventbus:3.2.0'

    //facial recognition
    implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.1.5'

}

kapt {
    correctErrorTypes true
}

当您不知道哪个版本运行良好时,您不需要指定版本,只需实施 platform('com.google.firebase:firebase-bom:29.1.0') 保留其他配置

您的应用程序中是否有 com.google.android.gms:play-services-base 依赖项? 你能尝试使用它的最新版本吗? 即:com.google.android.gms:play-services-base:17.6.0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM