Ubuntu Virtual Machine Compilation Android6.0 Summary

Source: Internet
Author: User

1 Preface

Yesterday using the source of Tsinghua download Android 6.0, the campus network can reach 10M speed, cool! Early in the morning, I can't wait to compile a simulator version, look at the effect, but it took a whole day to get it done ... To prevent others from wasting time on the same issues, record the problems and solutions that were encountered throughout the compilation process, after all, time is money!

2 background

I was installing the ubuntu14.04 64bit system on a Mac, initially allocating 3G of memory (the blood lessons are completely inadequate!). ), and two cores. The compiled system version is 6.0.1_R9 and 6.0.0_r26

3 problems and solutions encountered during the compilation process

The entire compilation process strictly according to the official website of the instructions, but because do not need to compile the source code, and in order to save space, so did not use CCache.

The compilation was successful at first, but the following error occurred when executing to the compile Java code (jar or DEX) stage:

Figure 3.1 Compilation Error feedback information

Apparently, a service called Jack didn't start, so what did Jack do? The interception of official website information is briefly summarized as follows:

Jack (Java Android Compiler Kit) is a new Android compilation tool used to compile Java code into Android Dex bytecode, mainly used to replace the previous compilation tool: Javac, Proguard, Jarjar and DX and so on. For more detailed information, refer to the website:

Https://source.android.com/source/jack.html#jack_intermediate_library_linker_jill

Jack's importance is self-evident, so if it does not start properly, our source code is categorically unable to compile. So why can't it start?

Check the official website with the following two tips:

  if your computer becomes unresponsive during compilation or If      You experience Jack compilations Failing on ' Out of memory error '   You can improve the situation by reducing the number of Jack simultaneous Compilations by editing your   $HOME/.jack and changing server_nb_compile to a lower value   . if your compilations is failing on "Cannot launch background server"   The most likely cause  is  TCP ports is already used on your computer. Try to change it by editing your $HOME/.jack (Server_port_service and Server_port_admin variables). 

Excluding the second case, I think the first situation is very likely, because from the Jack's startup parameters (from Figure 3.1 Compile error feedback information can be seen), the Java Virtual machine when the boot Jack allocated 2560M of memory, but my entire Ubuntu virtual machine only 3G Ah! So I immediately increased the memory of the Ubuntu virtual machine to 4G, and then recompile, but I did not make clean because the previous non-Java part of the compilation is not a problem, and the Java part of the compilation started out wrong, so do not need to be completely recompiled.

No, the tragedy is staged again! At that time two eyes flying blind, are ready to give up .... Halfway to consult the next before there has been a successful compilation experience of the classmate, thought is the version of the problem, so the 6.0.1_R9 switch to 6.0.0_r26 after the full recompile, long wait after the same problem occurs. Here's how to switch the source version:

① first enter the source root directory, the non- . repo/ files are all erased. ② View the switchable branch    CD. Repo/manifests    3     here choose 6. 0 . 0_r26 can ③ switch branches     -B android-6.0. 0 . 0_r26④ Sync Branch   repo sync      Note: Because I was syncing 6 before. 0. 1_r9 source code, so this step is completed quickly, according to the principle of git, do not need to re-download the entire source code, so here soon completed.

Obviously, this version of the system does not have much to do with, and continue to analyze why Jack could not start. The following log files are generated at the source root after each compilation failure:

From the name can be seen is some error log, open to see, the key information interception is as follows:

1 #2# there isInsufficient memory forThe Java Runtime environment toContinue.3#Native memory allocation (malloc) failed to allocate 1789919232 bytes for committing reserved memory.4 # Possible reasons:5# The System is  outof physical RAM or swap space6# in +bit mode, the process size limit is hit7 # Possible Solutions: 8 # Reduce Memory load on the System 9 # Increase physical memory or swap Space10 # Check if swap backing stor E is full One# Use -Bit Java on a -bit OS A# Decrease Java Heap Size (-xmx/-Xms) - # Decrease number of Java threads -# decrease Java Thread stack sizes (-Xss) the# Set larger code cache with-xx:reservedcodecachesize= - # This output file could be truncated or incomplete. - # -# Out of Memory Error (os_linux.cpp:2827), pid=101129, tid=47875161523968 + # -# JRE Version: (7.0_91-b02) (build) +# Java VM:OPENJDK --bit Server VM (24.91-B01 Mixed Mode linux-AMD64 compressed oops) A# Derivative:icedtea2.6.3 at# Distribution:ubuntu14.04LTS, Package 7u91-2.6.3-0ubuntu0.14.04.1 -# Failed to write core dump. Core dumps has been disabled. To enable core dumping,Try "Ulimit-c Unlimited"before starting Java again -#

The information from the red bold can be drawn as follows: When allocating memory for a Java virtual machine, it fails because the memory is not enough. However, according to my experience, 4G of memory, no matter how much is enough, then why the error? Look closely at the error log, which also mentions the "swap space problem." The problem may be on it! Swap partitions are primarily used to simulate extended physical memory using a hard disk in the case of insufficient physical memory, just a few orders of magnitude slower.

I don't remember whether the swap partition was allocated when the system was installed, so use the following command to see:

chouchou:~$ sudo swapon- for chouchou:filename                Type        Size    used     priority

The information is empty! That is, I do not have a swap partition, the following is the creation of partitions, here in order to facilitate the use of swap files in the way to achieve:

   -l 4G/Swapfile set////-for Chouchou : Filename                Type        Size    used    priority/swapfile                               file        4194300    345156    -1

Note: The swap partition created in this way is only valid for the current login state and is not valid after a reboot. As for how to achieve permanent effect, we can Google for ourselves.

Now compile again and pass at once! :

4 Summary

Compiling the source code spent a whole day, in addition to encountering Jack error, in the virtual machine inside the compiler is inefficient is an important factor. Because with the upgrading of the Android system, the source of the more and more large, the need for the compilation environment is also rising, so it is best to use solid machine compiler, and memory must be greater than 4g! In addition, encounter problems, the first time to view the error log is also critical, so often can not search for solutions, quickly locate the problem, save a lot of time!

Ubuntu Virtual Machine Compilation Android6.0 Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.