一、app运行报错
java.lang.OutOfMemoryError: Failed to allocate a 29859852 byte allocation with 3827656 free bytes
二、原因是内存不足,android app会限制应用申请的内存大小。
三、解决方案,可以在androidmenifest.xml文件中更改application配置,将hardwareAccelerated设置为false,largeHeap设置为true。
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/hyna_logo"
android:label="@string/app_name"
android:theme="@style/Theme.Spectrumcap"
tools:targetApi="31">
android:largeHeap = "true"
四、解释
android:hardwareAccelerated = "true"的时候会牺牲内存来进行硬件加速。
android:largeHeap = "false"会限制app应用申请的内存大小。
五、参考文章
解决“java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM”错误
解决“java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM”错误-CSDN博客