2

I'm trying to implement face detection in my Kotlin + Firebase app. I followed the ML Kit tutorial available in the ML site, but I keep getting an error related to the implementation in:

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)

I tried to use both ways

implementation 'com.google.mlkit:face-detection:16.0.6'

implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.1.5' with the meta-data added in manifest:

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

In both ways, I get the same error. Does anyone knows how to solve it?

This is the 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
}

2 Answers2

1

you dont need to specify a version when you don't know the version that works great , simply implementation platform('com.google.firebase:firebase-bom:29.1.0') leave the other configuration

jordy bayo
  • 409
  • 4
  • 3
0

Do you have com.google.android.gms:play-services-base dependency in your app? Could you try to use the latest version of it? which is: com.google.android.gms:play-services-base:17.6.0

Chenxi Song
  • 557
  • 3
  • 6
  • Both 'com.google.mlkit:face-detection:16.0.6' and 'com.google.android.gms:play-services-mlkit-face-detection:16.1.5' pull in 'play-service-base:17.6.0' in their pom files. Is it because in somewhere you force to pull in a lower version of play-service-base? – jack Apr 20 '21 at 18:57
  • I tried to insert the com.google.android.gms:play-services-base:17.6.0, but the error persists –  Apr 20 '21 at 19:02
  • Could you try "rm -rf ~/.m2/repository" to see if the old com.google.android.gms:play-services-base is somehow getting used due to cache? – Chenxi Song Apr 20 '21 at 19:13
  • how do I try this? Can you explain for me? I'm new to android development –  Apr 20 '21 at 19:14
  • Could you paste your entire build.gradle here so we can get more information? – jack Apr 20 '21 at 19:33
  • Guys, it worked! A friend of mine helped me with this, and he changed the version of the 'com.google.android.gms:play-services-mlkit-face-detection:16.1.5' to 'com.google.android.gms:play-services-mlkit-face-detection:16.1.2', and somehow it worked. Thanks for trying to help me! –  Apr 20 '21 at 19:37
  • 1
    Glad it worked. However could you still provide your build.gradle to help us on why 16.1.5 doesn't work? Thanks! – jack Apr 20 '21 at 19:41
  • Yes, I pasted the gradle –  Apr 20 '21 at 20:21
  • The build.gradle looks good. Could you check whether it has special setup in 1) your base project. 2) your "../version_control.gradle"? It would be helpful if you can also paste it here. Thanks! – jack Apr 20 '21 at 21:22