Xamarin.Firebase.ML.Natural.Language.Smart.Reply.Model Nuget Package not working on Xamarin.Android
Xamarin.Android Version (eg: 6.0):
Xamarin.Android SDK 10.3.1.0 Visual Studio Community 16.6.0
Operating System & Version (eg: Mac OSX 10.11):
Windows 10 Version 1903
Google Play Services Version
Xamarin.Firebase.ML.Natural.Language.Smart.Reply.Model: 120.0.7-preview02 Xamarin.Firebase.ML.Natural.Language.Smart.Reply: 118.0.7-preview02
Describe your Issue
Firebase Smart Reply Xamarin Android Binding is not working and throws an exception whenever I call the SuggestReplies() function. Looks like the model file is compressed. I have added the model file extension (.tflite) in project settings to keep it uncompressed.
Relevant information
Exception: This file can not be opened as a file descriptor; it is probably compressed. Probably the .tflite model file used by Smart Reply is not properly compressed. Also shows: com.google.firebase.ml.common.FirebaseMLException: Failed to generate smart reply
Add relevant project settings from *.csproj file:
<AndroidStoreUncompressedFileExtensions>.tflite;tflite</AndroidStoreUncompressedFileExtensions>
Packages used:
<PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Smart.Reply"> <Version>118.0.7-preview02</Version> </PackageReference>
<PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Smart.Reply.Model"> <Version>120.0.7-preview02</Version> </PackageReference>
Build settings (tools)
<AndroidDexTool>d8</AndroidDexTool>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
Steps to Reproduce (with link to sample solution if possible):
Just make a sample Xamarin.Android project using Xamarin.Firebase.ML.Natural.Language.Smart.Reply.Model Nuget package and call Smart Reply functions from sample code. Needs Firebase account.
Include any relevant Exception Stack traces, build logs, adb logs:
I/mono-stdout( 6829): Log: SmartReply Test 5 - Conversation
W/monodroid-assembly( 6829): typemap: unable to find mapping to a managed type from Java type 'com/google/android/gms/tasks/zzu'
I/mono-stdout( 6829): Log: 2nd call
I/mono-stdout( 6829): Log: Start Time: 5/23/2020 7:11:27 PM
W/monodroid-assembly( 6829): typemap: unable to find mapping to a managed type from Java type 'com/google/android/gms/tasks/zzu'
W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'System.Int32, mscorlib'
W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'System.Int32, mscorlib'
D/Mono ( 6829): DllImport searching in: '__Internal' ('(null)').
D/Mono ( 6829): Searching for 'java_interop_jnienv_is_assignable_from'.
D/Mono ( 6829): Probing 'java_interop_jnienv_is_assignable_from'.
D/Mono ( 6829): Found as 'java_interop_jnienv_is_assignable_from'.
I/tflite ( 6829): **Initialized TensorFlow Lite runtime.Initialized TensorFlow Lite runtime.**
W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'System.Int32, mscorlib'
E/ModelResourceManager( 6829): **Error preloading model resource**
E/ModelResourceManager( 6829): **com.google.firebase.ml.common.FirebaseMLException: Couldn't open language detection model file**
E/ModelResourceManager( 6829): at com.google.firebase.ml.naturallanguage.languageid.internal.LanguageIdentificationJni.zzl(com.google.firebase:firebase-ml-natural-language@@22.0.0:23)
E/ModelResourceManager( 6829): at com.google.firebase.ml.naturallanguage.languageid.FirebaseLanguageIdentification$zzb.zzl(com.google.firebase:firebase-ml-natural-language@@22.0.0:6)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde.zzf(com.google.firebase:firebase-ml-natural-language@@22.0.0:53)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde$zza.zzdn(com.google.firebase:firebase-ml-natural-language@@22.0.0:7)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde$zza.call(com.google.firebase:firebase-ml-natural-language@@22.0.0:24)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzco.zza(com.google.firebase:firebase-ml-natural-language@@22.0.0:31)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzcr.run(Unknown Source:4)
E/ModelResourceManager( 6829): at android.os.Handler.handleCallback(Handler.java:873)
E/ModelResourceManager( 6829): at android.os.Handler.dispatchMessage(Handler.java:99)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzb.dispatchMessage(com.google.firebase:firebase-ml-natural-language-smart-reply@@18.0.7:6)
E/ModelResourceManager( 6829): at android.os.Looper.loop(Looper.java:193)
E/ModelResourceManager( 6829): at android.os.HandlerThread.run(HandlerThread.java:65)
E/ModelResourceManager( 6829): **Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed**
E/ModelResourceManager( 6829): at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
E/ModelResourceManager( 6829): at android.content.res.AssetManager.openFd(AssetManager.java:768)
E/ModelResourceManager( 6829): at com.google.firebase.ml.naturallanguage.languageid.internal.LanguageIdentificationJni.zzl(com.google.firebase:firebase-ml-natural-language@@22.0.0:11)
E/ModelResourceManager( 6829): ... 11 more
W/monodroid-assembly( 6829): typemap: unable to find mapping to a Java type from managed type 'Android.Text.IInputFilter, Mono.Android'
W/FirebaseSmartReply( 6829): Failed to identify the language for the conversation
I/chatty ( 6829): uid=10090(com.kapildhaimade.) FirebaseMLHandl identical 3 lines
W/FirebaseSmartReply( 6829): **Failed to identify the language for the conversation**
@kapil-dhaimade
Can you prepare whole minimal repro project, please? I'm afraid that msbuild tasks might not process *.tflite file properly if at all. Not sure, but it might be necessary that I need to write some msbuild tasks.
@moljac Sure, just give me few days. I'll provide the minimal repro project. However, Firebase projects need the app SHA-1 key to be added to Firebase and I'm afraid you'd need to add your key to the project which I submit. Am I correct?
Also, I had tried manually adding another .tflite file to the Android assets and confirmed that it is uncompressed. However, the .tflite file shipped by the Smart Reply Nuget package is somehow not getting added to the build step itself I think.
@kapil-dhaimade
Just DO NOT provide your keys, please... people make mistakes and provide samples with API keys which is bad idea, because this is open source repo. Leave some kind of placeholders for those data.
I'll go and create and add my keys. Just provide me few short steps (with links) please, so i don't have to read all of the docs.
the .tflite file shipped by the Smart Reply Nuget package is somehow not getting added to the build step itself I think.
Could be. There are several bindings which need additional build steps. For example I bound Navigation, but it will need additional step for generating code. I'm preparing something with few local community people, but due to my tasks not much progress was made.
@moljac I have created the minimal repro project. It is a Xamarin.Android project and I have used Firebase SmartReply in MainActivity's OnCreate itself. Also, you need to put your Firebase keys in values.xml. Thanks.