zetbaitsu / Compressor

An android image compression library.
7.09k stars 963 forks source link

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

Open aliahsan-ch opened 4 years ago

aliahsan-ch commented 4 years ago

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)
r4phab commented 4 years ago

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

Is there anything we can do to prevent this crash ?

aliahsan-ch commented 4 years ago

@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.

adesamp commented 3 years ago

is this issue has fix version ?

khanjaved975 commented 3 years ago

is it fixed version now?

MahmoudMabrok commented 3 years ago

still issue occurs.

pradeep-orbi commented 3 years ago

Still facing this issue.

mochadwi commented 3 years ago

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

BraveEvidence commented 2 years ago

Any updates on this?

eric-ampire commented 2 years ago

Still have the issue