Build Android AOSP get this error :
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
some time the error "ninja failed with: exit status .....error, is cruse by this porblem.
this is two soution can sove this porblem.
1. buy more DDR memory to add your pc.
2. change JVM use monery space:
check my pc memory is :
cat /proc/meminfo
1 solve : my total memory is 8G, too smail for make AOSP, so can add 8G to 16G for this problem.
2. this let ours try to cange JVM use memory and swap size , check swapon size:
swapon -s
change swap size this this command, close swap:
swapoff /swapfile
delete it:
rm /swapfile
make new and more big size swap:
sudo fallocate -l 20G /swapfile
or
sudo dd if=/dev/zero of =/swapfile bs=1024 count=10485760
mkswap /swapfile
Enable swap:
swapon /swapfile
Check swap:
swapon -show
change JVM use swap and memory
echo 1 > /proc/sys/vm/overcommit_memory
This switch knows 3 different settings::
0: The Linux kernel is free to overcommit memory (this is the default), a heuristic algorithm is applied to figure out if enough memory is available.
1: The Linux kernel will always overcommit memory, and never check if enough memory is available. This increases the risk of out-of-memory situations, but also improves memory-intensive workloads.
2: The Linux kernel will not overcommit memory, and only allocate as much memory as defined in overcommit_ratio.
echo 75 > /proc/sys/vm/overcommit_ratio
Memory Allocation Limit = Swap Space + RAM * (Overcommit Ratio / 100)
留言列表