Forum Xamarin.Android

Firebase Smart Reply not working in Xamarin.Android

Hi! I am trying to use Firebase Smart Reply in my Xamarin.Android project. I followed the Firebase Guide and set it up in my project. However, it is not working and throws an exception whenever I call the SuggestReplies() function. I'm using Visual Studio 2019 16.6.0 version.

I've added following Nuget packages for Smart Reply:
<PackageReference Include="Xamarin.Firebase.ML.Natural.Language"> <Version>122.0.0-preview02</Version> </PackageReference> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Id.Model"> <Version>120.0.7-preview02</Version> </PackageReference> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Model"> <Version>120.0.7-preview02</Version> </PackageReference> <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> <PackageReference Include="Xamarin.Firebase.ML.Natural.Language.Translate"> <Version>122.0.0-preview02</Version> </PackageReference>

Also added following to disable compression of Smart Reply's model file:
<AndroidStoreUncompressedFileExtensions>.tflite;tflite</AndroidStoreUncompressedFileExtensions>

However, it throws the following exception on running:
com.google.firebase.ml.common.FirebaseMLException: Failed to generate smart reply

Also, the console logs show these lines before the exception is thrown:
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:[email protected]@22.0.0:23)
E/ModelResourceManager( 6829): at com.google.firebase.ml.naturallanguage.languageid.FirebaseLanguageIdentification$zzb.zzl(com.google.firebase:[email protected]@22.0.0:6)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde.zzf(com.google.firebase:[email protected]@22.0.0:53)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde$zza.zzdn(com.google.firebase:[email protected]@22.0.0:7)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzde$zza.call(com.google.firebase:[email protected]@22.0.0:24)
E/ModelResourceManager( 6829): at com.google.android.gms.internal.firebase_ml_naturallanguage.zzco.zza(com.google.firebase:[email protected]@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:[email protected]@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:[email protected]@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

I haven't been able to get it to run after much troubleshooting. I also tried to access the Smart Reply model asset file 'hobbes.tflite' using Assets.Open() and it worked.
Any idea how I can get this running? Thank you for the help :smile:

Sign In or Register to comment.