question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[CRASH] When used in flutter, Fileprovider paths can be overwritten

See original GitHub issue

Note: While this bug did affect me, i’m not sure if it is on you to fix it. cc @Sh1d0w , in case you feel responsible. I’m just filing it here to raise awareness, and to help others who have the same issue.

Describe the bug

We use this plug-in through multi_image_picker from flutter. When opening the camera, we got the following crash:

D/AndroidRuntime( 4819): Shutting down VM
E/AndroidRuntime( 4819): FATAL EXCEPTION: main
E/AndroidRuntime( 4819): Process: me.mcofficer.testapp, PID: 4819
E/AndroidRuntime( 4819): java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/DCIM/Camera/JPEG_20190730_085744_7657154079095321330.jpg
E/AndroidRuntime( 4819): at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:739)
E/AndroidRuntime( 4819): at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
E/AndroidRuntime( 4819): at com.sangcomz.fishbun.util.CameraUtil.takePicture(CameraUtil.java:41)
E/AndroidRuntime( 4819): at com.sangcomz.fishbun.ui.album.AlbumController.takePicture(AlbumController.java:132)
E/AndroidRuntime( 4819): at com.sangcomz.fishbun.ui.album.AlbumActivity$1.onClick(AlbumActivity.java:96)
E/AndroidRuntime( 4819): at android.view.View.performClick(View.java:6597)
E/AndroidRuntime( 4819): at android.view.View.performClickInternal(View.java:6574)
E/AndroidRuntime( 4819): at android.view.View.access$3100(View.java:778)
E/AndroidRuntime( 4819): at android.view.View$PerformClick.run(View.java:25885)
E/AndroidRuntime( 4819): at android.os.Handler.handleCallback(Handler.java:873)
E/AndroidRuntime( 4819): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 4819): at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime( 4819): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/AndroidRuntime( 4819): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 4819): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime( 4819): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/Process ( 4819): Sending signal. PID: 4819 SIG: 9
Lost connection to device.

To Reproduce Steps to reproduce the behavior:

  1. Create a flutter app with an android module
  2. define an authority and file provider paths in the module’s manifest. Make sure the authority matches your.flutter.app.provider, e.g. me.mcofficer.testapp.provider
  3. Implement multi_image_picker according to their instructions. Make sure to set enableCamera to true.
  4. Place a debug point on this line: https://github.com/sangcomz/FishBun/blob/9c48062802588367eaecfd20e791d9bb04f0f144/FishBun/src/main/java/com/sangcomz/fishbun/util/CameraUtil.java#L41
  5. Open your app, make it open fishbun, and tap the camera. You should hit the debug point; Step into getUriForFile and see what getPathStrategy(context, authority) returns.

Expected behavior The returned PathStrategy should be the one defined in FishBun’s AndroidManifest.xml. Once you resume execution, the camera should open.

Actual behavior The returned PathStrategy contains the paths from your flutter app’s module instead of those from FishBun. If these paths aren’t the same by chance, android will most likely fail to find the intended image file within these paths, resulting in above crash.

Smartphone (please complete the following information):

  • Device: As far as we know, any Android 9 device or Emulator. Specifically, a TA-1095 was used.
  • OS: Android N or greater, so the android X compatibility kicks in.
  • Version: multi_image_picker currently uses 0.10.0, but 0.11.0 is also affected.

The workaround is to either include FishBun’s provider path in your module’s paths, or to rename your module’s authority name so it doesn’t exactly match the one fishbun uses.

The solution on fishbun’s end might be to use a more distinct authority name, or perhaps check if that authority already exists.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sangcomzcommented, Sep 2, 2019

@Sh1d0w @MCOfficer

I released version 0.11.1. Please check and let me know. Thank you.

1reaction
MCOfficercommented, Jul 30, 2019

Hey. I don’t think the issue is related to the Flutter plugin. No where in the doc is suggested to add a file provider it should work out of the box without it. See the example app https://github.com/Sh1d0w/multi_image_picker/blob/master/example/android/app/src/main/AndroidManifest.xml

thanks for jumping on this so quickly. just to clarify, your instructions aren’t unclear - we require our own file provider for reasons unrelated to this package.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flutter share image intent - android - Stack Overflow
I've amended the answer with a possible fix, which involves changing the directory used to get the images from your existing dataDir to...
Read more >
<provider> | Android Developers
The substring nurses/rn is a path, which the content provider can use to identify subsets of the provider data.
Read more >
How to get away with READ/WRITE permissions on Android
Use FileProvider and the android ecosystem to create/edit/share files without asking users for Read and Write permissions.
Read more >
Fabric Crashlytics How to upload dSYM file in Jenkins with ...
[Solved]-Fabric Crashlytics How to upload dSYM file in Jenkins with Xcode ... I was building a macOS/iOS project, so used the following within...
Read more >
Felgo Update Guide
In case you use a lower Qt version, the paths will still use legacy external storage. On Android 10, you can add <application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found