preface

Recently, I set up a bureau with my friends to study the source code related to the framework. Learn the source code, the first is to download, compile the source code. Coincidentally, the source code for Android10 was just released this week, so I simply took it to study the framework

Because I am currently using the Mac book, but there will be various problems in the Mac environment for source code download and compilation, so I use Wmware to load the Ubanbu system to download and compile. Although we have solved some problems, we have also created new ones and filled in a lot of holes

This article is mainly to record the pit encountered and pit filling process, for other partners who have the same problem to pave the way, download and compile the source code as soon as possible, start source code learning

The body of the

Preparation stage

In the process of downloading and compiling source code, it really feels like all kinds of persuasion. Shall I start by telling you what hardware and software I’m preparing

Prepare listing

  • Mac, 16 gigabytes of ram
  • Solid state drive, 500 GB disk space
  • Vmware Fussion Mac version
  • Ubuntu 18.0.4 mirror
  • A ladder (you know) to read the documentation

Download the source code

When everything is ready (by default, you are already running ubantu in your virtual machine), you can set up the compilation and download environment, this is directly according to the official Google documentation to configure the relevant environment

After configuring the environment, you can prepare to download the source code, here we need to download the branch is Android_10.0.0-R2, because of the domestic network environment, here use Tsinghua source to replace Google’s download source to download, see this article, write very detailed, no repeat repeat

Also need to be reminded that the source of AOSP probably need about 100 g of disk space, if plus compilation, need at least 300 g, so in creating a virtual machine in advance when you need to allocate enough disk space, the physical disk space must also ensure enough, that’s why to list with solid-state drives. Of course, enough memory space can be ignored.

Also, the environment in which source code is downloaded and compiled is a memory partition format that must be distinguished, and the problems with download and compilation on the Mac are also greatly related to this

There are two most important instructions

$repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest - b android - 10.0.0 _r2 $repo syncCopy the code

The next step is to wait for the download to finish

The source code to compile

Congratulations on step 3. You’ve passed 90% of the people — because most of them are stuck on step 1

If you want to run it on a computer simulator, you’d better choose x86 architecture after lunch to compile

Since we are running in a virtual machine environment, the biggest problem I encountered in this step was only one: the process was killed due to insufficient memory. I even compiled 90% of the time, and the process was killed due to insufficient memory.

Without adding existing hardware, I took two approaches

Method 1: Allocate more memory and CPU cores to the virtual machine (to speed up compilation)

My Mac host has 16 gigabytes of ram, and I’ve allocated 12 gigabytes to the virtual machine. You can do what you like, the more the better

Method 2: Increase the size of the SWAP space

This specific principle has not been studied in depth, anyway, reference to this article to solve. Note that an increase of 2048MB is not enough (experience with multiple compile failures…). The only time I did it, it went straight up to 8192MB

During compilation, you can also open a terminal window to view the real-time memory usage through the TOP command

The following compilation takes about 3-8 hours, depending on the hardware, you can take a break…

Run the compiled image

This step is basically complete, so let’s run our compiled image! Run the emulator on the emulator. And after a long time… For a long time… For a long time… I find it just doesn’t work

Since the direct use of instructions can not work, then let’s change the way of thinking, to replace the pillar stealthily!

Open the familiar tool AS and create an AVD virtual machine using the official image provided by Android10. /out/target/product = /out/target/product = /out/target/product = /out/target/product I refer to this article and find the compiled core file

  • Linux Kernel
  • system.img
  • userdata.img
  • ramdisk.img

Replace these four files with the directory where you created the AVD emulator, then run the emulator through AS, and if anything, you should see compiled Android10 up and running.

Congratulations, all downloads and compilations are complete, but learning the framework has just begun

Together, keep it up!

Afterword.

We did encounter a lot of problems in the process of downloading and compiling. Thank you for the guidance of Lu Yao brother brother, and the learning community shen Nong class provided by Ala Shen Nong (Teacher Deng), as well as the valuable advice provided by friends studying together

The most important thing is, don’t give up when something is difficult, conquer it, take it, and learn from it

The last

Think so? Why don’t you just like it and follow it?