Compressor icon indicating copy to clipboard operation
Compressor copied to clipboard

BitmapFactory.decodeFile(absolutePath, this) must not be null

Open aliahsan-ch opened this issue 5 years ago • 9 comments

Implementation:

val originalPhotoFile = File(originalPhotoPath ?: return)
lifecycleScope.launch {
                 val compressedPhotoPath = Compressor.compress(requireContext(),originalPhotoFile)
                }

Exception:

Fatal Exception: java.lang.IllegalStateException: BitmapFactory.decodeFile…eFile.absolutePath, this) must not be null
       at id.zelory.compressor.UtilKt.decodeSampledBitmapFromFile(Util.kt:45)
       at id.zelory.compressor.constraint.DefaultConstraint.satisfy(DefaultConstraint.kt:28)
       at id.zelory.compressor.Compressor$compress$3.invokeSuspend(Compressor.kt:28)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

aliahsan-ch avatar Sep 15 '20 23:09 aliahsan-ch

Same issue on multiple Xiaomi devices and a P30 Pro for now .... 👎🏻

Is there anything we can do to prevent this crash ?

r4phab avatar Oct 13 '20 07:10 r4phab

@r4phab Currently, as a workaround, we have created an extension function to fall back to the uncompressed file in case of an exception but this should be fixed.

aliahsan-ch avatar Oct 13 '20 08:10 aliahsan-ch

is this issue has fix version ?

adesamp avatar Mar 25 '21 04:03 adesamp

is it fixed version now?

khanjaved975 avatar Jun 16 '21 14:06 khanjaved975

still issue occurs.

MahmoudMabrok avatar Jun 29 '21 08:06 MahmoudMabrok

Still facing this issue.

pradeep-orbi avatar Jul 14 '21 17:07 pradeep-orbi

This might be happened, if we try to create a temporary file (not an image type).

In our case:

  1. we make sure when creating temporary files (before take picture/open camera)
  2. 1do nothing for the files (no compression)
  3. afterward onActivityResult called, the Uri now used either to update the previous temporary files or try to compress the Uri (convert it to a File first)

This is also sometimes related to Android 10 & above permission, when trying to open/retrieve files from /Android/data, as mentioned in here: https://developer.android.com/about/versions/11/privacy/storage#file-access

mochadwi avatar Nov 22 '21 04:11 mochadwi

Any updates on this?

BraveEvidence avatar Jun 21 '22 04:06 BraveEvidence

Still have the issue

eric-ampire avatar Oct 16 '22 07:10 eric-ampire