flutter_image_compress
flutter_image_compress copied to clipboard
Out of Memory Error on Android 6.0
We are seeing the following error for our users on Android 6 with Samsung devices. Running version 0.6.2.
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 26211852 byte allocation with 16777216 free bytes and 21MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
at android.graphics.Bitmap.nativeCreate(Bitmap.java)
at android.graphics.Bitmap.createBitmap + 975(Bitmap.java:975)
at android.graphics.Bitmap.createBitmap + 946(Bitmap.java:946)
at android.graphics.Bitmap.createBitmap + 877(Bitmap.java:877)
at com.example.flutterimagecompress.ext.BitmapCompressExtKt.compress(BitmapCompressExtKt.java)
at com.example.flutterimagecompress.ext.BitmapCompressExtKt.compress(BitmapCompressExtKt.java)
at com.example.flutterimagecompress.ext.BitmapCompressExtKt.compress(BitmapCompressExtKt.java)
at com.example.flutterimagecompress.core.CompressFileHandler$handle$1.run(CompressFileHandler.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1113(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 588(ThreadPoolExecutor.java:588)
at java.lang.Thread.run + 818(Thread.java:818)
Our only call to the library is this :
var result = await FlutterImageCompress.compressWithFile(file.absolute.path,
rotate: rotationCorrection);
Same problem of #76 .
Can you provide a image as an attachment?
By the way, is there a problem with the same image in ios?
I don't have an example image as we are seeing this in the wild and not able to reproduce locally as we do not have the device. It is coming through as crash reports from our logging service.
We are not seeing this error at all on IOS. We have seen a number of these crashes and 100% of them have been Android 6 on Samsung devices only.
OK, thx for issue, I will fix it as soon as possible.
Because my android 9.0 device does not use a similar error even if I don't use SampleSize, I need human support testing.
dependencies:
flutter_image_compress:
git:
url: https://github.com/OpenFlutter/flutter_image_compress.git
ref: 2254a73ef9cfb2458d8cf54902c24d39cc263a49
If the test passes, I will push this change to the new version.
Because my android 9.0 device does not use a similar error even if I don't use SampleSize, I need human support testing.
dependencies: flutter_image_compress: git: url: https://github.com/OpenFlutter/flutter_image_compress.git ref: 2254a73ef9cfb2458d8cf54902c24d39cc263a49
For me this solution is not working :( Small images working very well, but on big images the plugin will return null as result.
I'm unable to provide support testing as this is happening to our users in the wild, we do not have the devices to reproduce it ourselves.
This is my solution, set inSampleSize before compressing
double _getScale(Wallpaper wallpaper) {
var scale1 = wallpaper.dimension_x / 768;
var scale2 = wallpaper.dimension_y / 1024;
return scale1 > scale2 ? scale2 : scale1;
}
await FlutterImageCompress.compressAndGetFile(
_file.absolute.path,
_path,
minWidth: _isLandscape ? 1920 : 1080,
minHeight: _isLandscape ? 1080 : 1920,
inSampleSize: _scale.toInt(),
quality: 88,
);
inSampleSize
Why do you have a parameter called "inSampleSize"? My "compressAndGetFile" looks like that:

I found a fix for my problem! 😍
So first of all: The reason for my crash was not the Out of Memory Error. It was FileSystemException: FileSystemException: Cannot open file, path = '.../.flutter-plugins' (OS Error: Permission denied, errno = 13). But the FlutterImageCompress Plugin doesn't catch this exception. So my app crashed. Because of the crash, it was very hard, to find the real exception. Additional this was only a problem for android 10. Finally I figured it out (I named the exception already with permission denied).
In this issue is explained, why the permission denied exception come up: https://github.com/miguelpruivo/flutter_file_picker/issues/169
A workaround for this exception is: Add <application android:requestLegacyExternalStorage="true" to your AndroidManifest.xml.
I hope that I can help some people, who had the same issue :)
I found a fix for my problem! 😍
So first of all: The reason for my crash was not the
Out of Memory Error. It wasFileSystemException: FileSystemException: Cannot open file, path = '.../.flutter-plugins' (OS Error: Permission denied, errno = 13). But the FlutterImageCompress Plugin doesn't catch this exception. So my app crashed. Because of the crash, it was very hard, to find the real exception. Additional this was only a problem for android 10. Finally I figured it out (I named the exception already with permission denied).In this issue is explained, why the permission denied exception come up: miguelpruivo/flutter_file_picker#169
A workaround for this exception is: Add
<application android:requestLegacyExternalStorage="true"to your AndroidManifest.xml.I hope that I can help some people, who had the same issue :)
Let friends who have the same problem try your solution, thanks for replying.
Same issue here, any update?
Stuck in the same place, anybody found a fix?