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.

StrictMode DiskReadViolation when loading image File from disk

See original GitHub issue

Describe the bug I load an image “file://” Uri from disk. Coil obviously loads it on main thread, or at least does an “last modified time” check on main thread. I even tried specifying IO dispatcher with imageView.load(fileUri) { dispatcher(Dispatchers.IO) } but it doesn’t help.

Expected behavior Expected behaviour is that disk should never be touched from main thread.

To Reproduce imageView.load(fileUri) where file Uri is a literal “file://” Uri.

Logs/Screenshots

2020-05-02 22:04:02.901 27160-27160/com.berry4u.app D/StrictMode: StrictMode policy violation; ~duration=5 ms: android.os.strictmode.DiskReadViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1556)
        at java.io.UnixFileSystem.getLastModifiedTime(UnixFileSystem.java:289)
        at java.io.File.lastModified(File.java:939)
        at coil.fetch.FileFetcher.key(FileFetcher.kt:14)
        at coil.fetch.FileFetcher.key(FileFetcher.kt:12)
        at coil.RealImageLoader$executeInternal$2$deferred$1.invokeSuspend(RealImageLoader.kt:525)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
        at kotlinx.coroutines.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:337)
        at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:158)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:54)
        at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
        at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
        at coil.RealImageLoader.execute(RealImageLoader.kt:143)

Version 0.10.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
PaulWoitaschekcommented, Feb 11, 2022
2reactions
colinrtwhitecommented, May 27, 2020

Coil synchronously fulfills images in the memory cache (to avoid white flashes) so it’s not possible to move the check to a background thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

StrictMode - Android Developers
StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and ......
Read more >
What is strict mode policy violation in Android - Stack Overflow
(1) It turns out that Strict mode doesn't actually prevent you from making writes to the disk it just gives a warning.
Read more >
Smooth Operator: Using StrictMode to make your Android App ...
You can see it points out that its a DiskReadViolation and points to ... "/path/to/image.jpg") GlideApp.with(itemView.context) .load(file) ...
Read more >
AdManager SDK for Android throwing StrictMode violation for ...
The AdManager SDK for Android's PublisherAdView is throwing strict mode ... ReadFromDisk Violation - Ad First Load: ... isDirectory(File.java:845)
Read more >
core/java/android/os/StrictMode.java - platform/frameworks/base
you may not use this file except in compliance with the License. ... <p>StrictMode is most commonly used to catch accidental disk or...
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