【问题标题】:Can't use the ML Kit in android development无法在 android 开发中使用 ML Kit
【发布时间】:2021-07-14 22:16:32
【问题描述】:

我正在尝试在我的 Kotlin + Firebase 应用中实现人脸检测。我按照 ML 站点中提供的 ML Kit 教程进行操作,但我不断收到与 implementation 相关的错误:

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" />

在这两种方式中,我都会遇到同样的错误。有人知道怎么解决吗?

这是毕业典礼:

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
}

【问题讨论】:

    标签: android kotlin build.gradle google-mlkit


    【解决方案1】:

    不知道哪个版本好用时不需要指定版本,只需实现平台('com.google.firebase:firebase-bom:29.1.0') 保留其他配置

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • “com.google.mlkit:face-detection:16.0.6”和“com.google.android.gms:play-services-mlkit-face-detection:16.1.5”都加入了'play-service-base:17.6.0' 在他们的 pom 文件中。是不是因为在某个地方你强行引入了较低版本的 play-service-base?
      • 我尝试插入 com.google.android.gms:play-services-base:17.6.0,但错误仍然存​​在
      • 你能试试“rm -rf ~/.m2/repository”看看旧的 com.google.android.gms:play-services-base 是否因为缓存而被使用?跨度>
      • 我该如何尝试?你能给我解释一下吗?我是 android 开发新手
      • 很高兴它成功了。但是,您是否仍然可以提供您的 build.gradle 来帮助我们了解为什么 16.1.5 不起作用?谢谢!
      猜你喜欢
      • 1970-01-01
      • 2020-11-09
      • 2021-12-06
      • 1970-01-01
      • 2019-10-12
      • 2020-12-26
      • 2020-05-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多