stripe / stripe-android

Stripe Android SDK
https://stripe.com/docs/mobile/android
MIT License
1.26k stars 640 forks source link

[BUG] Fatal Exception: java.lang.IllegalArgumentException: ... does not encode a valid TensorFlow Lite model: Could not open .... The model allocation is null/empty #7347

Open jamesbluecrow opened 12 months ago

jamesbluecrow commented 12 months ago

Summary

We are seeing some our app crashing sometimes (not many) with the exception below.

Fatal Exception: java.lang.IllegalArgumentException: Contents of /data/user/0/com.package/cache/a8bcf0129dcd29084f6797ede7e0be86f9e11ed5.tflite does not encode a valid TensorFlow Lite model: Could not open '/data/user/0/com.package/cache/a8bcf0129dcd29084f6797ede7e0be86f9e11ed5.tflite'.
The model allocation is null/empty
       at org.tensorflow.lite.NativeInterpreterWrapper.createModel(NativeInterpreterWrapper.java)
       at org.tensorflow.lite.NativeInterpreterWrapper.<init>(NativeInterpreterWrapper.java:57)
       at org.tensorflow.lite.Interpreter.<init>(Interpreter.java:197)
       at com.stripe.android.mlcore.impl.InterpreterWrapperImpl.<init>(InterpreterWrapperImpl.kt:11)
       at com.stripe.android.identity.ml.FaceDetectorAnalyzer.<init>(FaceDetectorAnalyzer.kt:29)
       at com.stripe.android.identity.ml.FaceDetectorAnalyzer$Factory.newInstance(FaceDetectorAnalyzer.kt:98)
       at com.stripe.android.camera.framework.AnalyzerPool$Companion.of(Analyzer.kt:45)
       at com.stripe.android.camera.framework.AnalyzerPool$Companion.of$default(AnalyzerPool.java:39)
       at com.stripe.android.identity.camera.IdentityScanFlow$startFlow$1.invokeSuspend(IdentityScanFlow.kt:95)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:110)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_common.kt:56)
       at kotlinx.coroutines.BuildersKt.launch(Builders.kt:1)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(BuildersKt__Builders_common.kt:47)
       at kotlinx.coroutines.BuildersKt.launch$default(Builders.kt:1)
       at com.stripe.android.identity.camera.IdentityScanFlow.startFlow(IdentityScanFlow.kt:82)
       at com.stripe.android.identity.viewmodel.IdentityScanViewModel.startScan(IdentityScanViewModel.java:48)
       at com.stripe.android.identity.utils.CameraUtilsKt.startScanning(CameraUtils.kt:16)
       at com.stripe.android.identity.ui.SelfieScreenKt$SelfieScanScreen$2$3.invoke(SelfieScreen.kt:202)
       at com.stripe.android.identity.ui.SelfieScreenKt$SelfieScanScreen$2$3.invoke(SelfieScreen.kt:195)
       at com.stripe.android.identity.ui.CameraScreenLaunchedEffectKt$CameraScreenLaunchedEffect$1$1.invoke(CameraScreenLaunchedEffect.kt:57)
       at com.stripe.android.identity.ui.CameraScreenLaunchedEffectKt$CameraScreenLaunchedEffect$1$1.invoke(CameraScreenLaunchedEffect.kt:47)
       at com.stripe.android.identity.ui.CameraScreenLaunchedEffectKt$sam$androidx_lifecycle_Observer$0.onChanged(CameraScreenLaunchedEffect.kt:13)
       at androidx.lifecycle.LiveData.considerNotify(LiveData.java:133)
       at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:146)
       at androidx.lifecycle.LiveData$ObserverWrapper.activeStateChanged(LiveData.java:483)
       at androidx.lifecycle.LiveData$LifecycleBoundObserver.onStateChanged(LiveData.java:440)
       at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
       at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.kt:192)
       at androidx.lifecycle.LiveData.observe(LiveData.java:205)
       at com.stripe.android.identity.ui.CameraScreenLaunchedEffectKt$CameraScreenLaunchedEffect$1.invokeSuspend(CameraScreenLaunchedEffect.kt:47)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
       at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
       at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8757)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

Code to reproduce

No repro steps available. It has happened only to a few users.

Android version

Android 12 & 13

Impacted devices

Installation method

Through a gradle dependency

Dependency Versions

kotlin: 1.9.0 stripe-android: 20.31.0 Android Gradle Plugin: 8.1.1 Gradle: 8.3

tillh-stripe commented 12 months ago

@ccen-stripe, can you help out here?

ccen-stripe commented 12 months ago

hi @jamesbluecrow the .tflite model is downloaded on the fly, from the log it seems that the file is not correctly downloaded. Is it possible to confirm when the error happens network connection is not stable and the model fails to download?

jamesbluecrow commented 12 months ago

IllegalArgumentException

Yes it is likely due to slow internet connection.

But in no case should the app crash because of it. The SDK should catch that exception if it cannot load the model and maybe emit a IdentityVerificationSheet.VerificationFlowResult.Failed error.

Because it is happening inside the SDK we cannot catch that exception ourselves.

ccen-stripe commented 11 months ago

IllegalArgumentException

Yes it is likely due to slow internet connection.

But in no case should the app crash because of it. The SDK should catch that exception if it cannot load the model and maybe emit a IdentityVerificationSheet.VerificationFlowResult.Failed error.

Because it is happening inside the SDK we cannot catch that exception ourselves.

Will fix this in our upcoming release!

thedeveloperr commented 1 month ago

Hi, any plans/ETA for the fix for this or is it fixed already ? We are still seeing this. Our version SDK is v20.48