geweald / flutter_onfido

Flutter Onfido Plugin
MIT License
8 stars 20 forks source link

App crashes when opening camera #1

Closed juliano closed 3 years ago

juliano commented 3 years ago

Hello there. First of all, thanks for this project, it's gold!

I added flutter_onfido to my project, and in summary it works for ios and fails with android. Running the example in the repo, when clicking "Enable camera", the application crashes.

Here is the exception ``` D/AndroidRuntime( 9355): Shutting down VM E/AndroidRuntime( 9355): FATAL EXCEPTION: main E/AndroidRuntime( 9355): Process: app.broad, PID: 9355 E/AndroidRuntime( 9355): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.broad/com.onfido.android.sdk.capture.ui.camera.CaptureActivity}: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ E/AndroidRuntime( 9355): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449) E/AndroidRuntime( 9355): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) E/AndroidRuntime( 9355): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) E/AndroidRuntime( 9355): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) E/AndroidRuntime( 9355): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) E/AndroidRuntime( 9355): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) E/AndroidRuntime( 9355): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime( 9355): at android.os.Looper.loop(Looper.java:223) E/AndroidRuntime( 9355): at android.app.ActivityThread.main(ActivityThread.java:7656) E/AndroidRuntime( 9355): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 9355): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/AndroidRuntime( 9355): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) E/AndroidRuntime( 9355): Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ E/AndroidRuntime( 9355): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226) E/AndroidRuntime( 9355): at com.google.gson.Gson.fromJson(Gson.java:927) E/AndroidRuntime( 9355): at com.google.gson.Gson.fromJson(Gson.java:892) E/AndroidRuntime( 9355): at com.google.gson.Gson.fromJson(Gson.java:841) E/AndroidRuntime( 9355): at com.google.gson.Gson.fromJson(Gson.java:813) E/AndroidRuntime( 9355): at com.onfido.api.client.token.sdk.SDKToken.buildUrl(SDKToken.java:37) E/AndroidRuntime( 9355): at com.onfido.api.client.OnfidoAPIFactory.create(OnfidoAPIFactory.java:34) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.utils.OnfidoApiUtil.createOnfidoApiClient(Unknown Source:18) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.common.di.SdkModule.provideOnfidoAPI(Unknown Source:9) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.common.di.SdkModule_ProvideOnfidoAPIFactory.get(Unknown Source:10) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.common.di.SdkModule_ProvideOnfidoAPIFactory.get(Unknown Source:0) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.common.di.SdkModule_ProvideOnfidoApiServiceFactory.get(Unknown Source:4) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.common.di.SdkModule_ProvideOnfidoApiServiceFactory.get(Unknown Source:0) E/AndroidRuntime( 9355): at com.onfido.dagger.internal.a.get(Unknown Source:13) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.ui.camera.CaptureActivity_MembersInjector.injectMembers(Unknown Source:34) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.ui.camera.CaptureActivity_MembersInjector.injectMembers(Unknown Source:2) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.common.di.DaggerSdkComponent.inject(Unknown Source:2) E/AndroidRuntime( 9355): at com.onfido.android.sdk.capture.ui.camera.CaptureActivity.onCreate(Unknown Source:20) E/AndroidRuntime( 9355): at android.app.Activity.performCreate(Activity.java:8000) E/AndroidRuntime( 9355): at android.app.Activity.performCreate(Activity.java:7984) E/AndroidRuntime( 9355): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) E/AndroidRuntime( 9355): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) E/AndroidRuntime( 9355): ... 11 more E/AndroidRuntime( 9355): Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ E/AndroidRuntime( 9355): at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385) E/AndroidRuntime( 9355): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:215) E/AndroidRuntime( 9355): ... 32 more I/Process ( 9355): Sending signal. PID: 9355 SIG: 9 Lost connection to device. ```

Even though everything indicates it's a problem with Onfido parsing JSON, I thought you could have some advice dealing with this problem :)

flutter doctor output: ``` [✓] Flutter (Channel beta, 1.25.0-8.1.pre, on macOS 11.1 20C69 darwin-x64, locale en-GB) • Flutter version 1.25.0-8.1.pre at /Users/juliano/bin/flutter • Framework revision 8f89f6505b (3 weeks ago), 2020-12-15 15:07:52 -0800 • Engine revision 92ae191c17 • Dart version 2.12.0 (build 2.12.0-133.2.beta) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/juliano/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.3, Build version 12C33 • CocoaPods version 1.10.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) [✓] IntelliJ IDEA Community Edition (version 2020.3.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart [✓] Connected device (3 available) • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • iPhone 12 Pro Max (mobile) • 372621A5-FFA8-4221-90E2-456F2B7C300E • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88 ```

Thank you in advance!

geweald commented 3 years ago

Hi @juliano thanks! I'll take a look this week, you can quickly try if adding permission to AndroidManifest.xml of your project fixes it

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
juliano commented 3 years ago

Hi @geweald thank you for looking into it!

I've tried your suggestion already, unfortunately hasn't solved the problem :/

juliano commented 3 years ago

Alright, I managed to find the problem. In development, I was trying to use a mobile token instead of an sdk token. Instead of telling me it was invalid, onfido tries to parse the result, crashing the app. After generating and using and sdk token, it works.

Interesting enough, if I try to use an invalid sdk token, the camera still works.

Thanks for supporting me here!