googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.55k stars 2.93k forks source link

[Bug report] [Android] java.lang.IllegalArgumentException: Model name expected to be matching [a-z]{2,3}_[a-z]{2,3} #828

Closed bybrs closed 3 months ago

bybrs commented 5 months ago

Describe the bug Hello, when you call isModelDownloaded method on RemoteModelManager instance having a TranslateRemoteModel parameter with unexpected model name, you get the following error:

com.google.android.gms.tasks.RuntimeExecutionException: java.lang.IllegalArgumentException: Model name expected to be matching [a-z]{2,3}_[a-z]{2,3}
    at com.google.android.gms.tasks.zzw.getResult(com.google.android.gms:play-services-tasks@@18.0.2:3)
    at com.google.mlkit.nl.translate.internal.zzan.zzf(com.google.mlkit:translate@@17.0.1:1)
    at com.google.mlkit.nl.translate.internal.zzam.onComplete(Unknown Source:2)
    at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.2:1)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7839)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.IllegalArgumentException: Model name expected to be matching [a-z]{2,3}_[a-z]{2,3}
    at com.google.mlkit.nl.translate.internal.zzad.zzg(com.google.mlkit:translate@@17.0.1:2)
    at com.google.mlkit.nl.translate.internal.zzad.zza(com.google.mlkit:translate@@17.0.1:1)
    at com.google.mlkit.nl.translate.internal.zzi.zzj(com.google.mlkit:translate@@17.0.1:4)
    at com.google.mlkit.nl.translate.internal.zzac.zzf(com.google.mlkit:translate@@17.0.1:1)
    at com.google.mlkit.nl.translate.internal.zzan.zzc(com.google.mlkit:translate@@17.0.1:1)
    at com.google.mlkit.nl.translate.internal.zzal.then(Unknown Source:4)
    at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks@@18.0.2:3)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.os.HandlerThread.run(HandlerThread.java:67)

To Reproduce

  1. Identify language of a text using the following code, which can return "ar-Latn" on its onSuccess callback:
    import com.google.mlkit.nl.languageid.LanguageIdentification
    ...
    LanguageIdentification.getClient().identifyLanguage(text)
    .addOnSuccessListener {
        if (it == "ar-Latn") ... 
    }
  2. Try to call isModelDownloaded method on RemoteModelManager instance having a TranslateRemoteModel parameter created with the "ar-Latn" language from the previous step:
    import com.google.mlkit.common.model.RemoteModelManager
    import com.google.mlkit.nl.translate.TranslateRemoteModel
    ...
    val modelManager = RemoteModelManager.getInstance()
    val translateRemoteModel = TranslateRemoteModel.Builder("ar-Latn").build()
    modelManager.isModelDownloaded(translateRemoteModel) // >>> This is where the crash happens inside mlkit library
  3. Application crashes

Expected behavior A clear and concise description of what you expected to happen.

SDK Info: Still exist in the latest versions of these libraries but the one I had used are the following:

Smartphone: Might not be device/OS specific, but I can repeatedly reproduce this issue on the following simulator:

zhouyiself commented 3 months ago

"ar-Latn" is not a supported language from the Translation API. Here is the full supported language list https://developers.google.com/android/reference/com/google/mlkit/nl/translate/TranslateLanguage