【发布时间】:2020-04-06 05:11:24
【问题描述】:
场景
我正在开发 android 应用程序,它下载加密的视频文件,将其保存在内存中,然后当用户从 android 应用程序单击该文件的播放按钮时解密它。解密后播放该视频。
问题
应用程序在大多数设备上都能正常运行。但是在 Redmi note 4 中(根据我对 3 个不同的 Redmi note 4 的测试)它给出了例外
Throwing OutOfMemoryError "Failed to allocate a 27394783 byte allocation with 15063472 free bytes and 14MB until OOM
Android Menifest.xml
android:name=".receiver.ConnectivityListener"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:largeHeap="true"
android:supportsRtl="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyMaterialTheme"
android:usesCleartextTraffic="true"
在 build.gradle 中
dexOptions {
incremental true
javaMaxHeapSize "4g"
preDexLibraries true
dexInProcess = true
}
日志猫
2020-03-21 15:23:40.733 19593-19699/com.ehiddenbrain.prod I/art: Forcing collection of SoftReferences for 26MB allocation
2020-03-21 15:23:40.733 19593-19699/com.ehiddenbrain.prod I/art: Starting a blocking GC Alloc
2020-03-21 15:23:40.767 19593-19699/com.ehiddenbrain.prod I/art: Clamp target GC heap from 513MB to 512MB
2020-03-21 15:23:40.767 19593-19699/com.ehiddenbrain.prod I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 2% free, 497MB/512MB, paused 435us total 33.194ms
2020-03-21 15:23:40.767 19593-19699/com.ehiddenbrain.prod W/art: Throwing OutOfMemoryError "Failed to allocate a 27394783 byte allocation with 15063472 free bytes and 14MB until OOM"
2020-03-21 15:23:40.778 19593-19699/com.ehiddenbrain.prod E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #9
Process: com.ehiddenbrain.prod, PID: 19593
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:760)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 27394783 byte allocation with 15063472 free bytes and 14MB until OOM
at com.android.org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineDoFinal(BaseBlockCipher.java:1112)
at javax.crypto.Cipher.doFinal(Cipher.java:2056)
at com.example.ehiddenbrain_v03.utility.Decoder.decryptVideo(Decoder.java:56)
at com.example.ehiddenbrain_v03.background.DecoderBackgroundTask.doInBackground(DecoderBackgroundTask.java:66)
at com.example.ehiddenbrain_v03.background.DecoderBackgroundTask.doInBackground(DecoderBackgroundTask.java:26)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:760)
2020-03-21 15:23:40.779 19593-19699/com.ehiddenbrain.prod W/AndroidRuntime: finished raiseRlimit, rlim_cur:4096 rlim_max:4096
2020-03-21 15:23:40.945 19593-19696/com.ehiddenbrain.prod V/FA: Recording user engagement, ms: 4696
2020-03-21 15:23:40.947 19593-19696/com.ehiddenbrain.prod V/FA: Activity paused, time: 240603587
如果有人知道这个问题,请帮助我... 谢谢!!!
【问题讨论】:
-
嗯?它说它没有足够的内存。
-
是的,先生,内存不足异常@chrylis-onstrike-
-
但设备中有可用内存。那么为什么它发生在 3 个不同的 Redmi Note 4 设备上而不是其他设备上? @user85421
-
内存中有 11.37 GB 可用。 @RandallArms
-
logcat 添加有问题。 @RandallArmsJr.
标签: java android android-studio exception out-of-memory