Android System Chapter (1) - Establishing the Android System Development Environment

"In-depth analysis of Android 5.0 system" book notes

Before starting to study the Android system, we need to prepare some development materials, such as Ubuntu, source code, development materials, etc. The Android system itself is very huge. The application uses the JAVA language, and the bottom layer uses C/C++. Therefore, If possible, try to master as much as possible.

一 .Free

We are more likely to choose Window + Ubuntu for work, so we will rely more on virtual machines, which have been introduced in my previous blog, and will not be repeated here.

Android source code analysis (1) - VMware Workstation Pro and Ubuntu Kylin 16.04 LTS installation configuration

Android source code analysis (2) - Ubuntu Root, Git, VMware Tools, install input method, theme beautification, Dock, install JDK and configure the environment

Analysis of Android source code (3) - Synchronous sync and compile make of Android AOSP 5.1.1 source code, build Samba server for more convenient burning and flashing

Android source code analysis (4) - adb commands, Linux commands, and source code compilation commands that I commonly use in Android development

Android source code analysis (5) - about custom system, how to sign your Android application system

Android source code analysis (6) - SecureCRT remote connection to Linux, configuration endpoints and bytecode

Here I choose the latest Ubuntu 17.10.1 to try it out.

Next, we need to install some necessary tools, such as git, vim, etc. Let's take a look at the command

sudo apt-get install git

sudo apt-get install vim

sudo apt-get install repo

sudo apt-get install curl

sudo apt-get install make

At this point, our preparations are all right, we now need to prepare some development tools

2. Development tools

We need to install something that is convenient for us to develop, such as JDK

1.JDK

What I installed here is JDK1.7. If you want to download it, you can search for the following on your official website or other places and you will come out.

//解压
sudo tar zxvf jdk-7u79-linux-x64.tar.gz 
//移动
sudo mv jdk1.7.0_79 /usr/lib/jdk/
//配置
vim ~/.bashrc
//末尾处
export JAVA_HOME=/usr/lib/jdk/jdk1.7.0_79
export JRE_HOME=${JAVA_HOME}/jre   
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib   
export PATH=${JAVA_HOME}/bin:$PATH   

2.OpenJDK

sudo add-apt-repository ppa:openjdk-r/ppa  
sudo apt-get update   
sudo apt-get install openjdk-7-jdk

3.Android Studio/SDK

Android Studio Chinese Community

Download and unzip, and then automatically install the SDK, provided that there is a JDK

4.Source Insight

Source Insight

Source Insight is an artifact that can be easily searched to find the content in the source code

3. Download the source code

PS: Refer to the Google tutorial https://source.android.com/source/downloading.html , replace https://android.googlesource.com/ with https://aosp.tuna.tsinghua.edu.cn/ Can.

It is actually not that easy to download a source code in China...

Here we go through the source of Tsinghua University to download

Tsinghua University Open Source Software Mirror Site

1. Download the repo

mkdir ~/bin
PATH=~/bin:$PATH
curl https://aosp.tuna.tsinghua.edu.cn/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

write picture description here

The code here should be well understood, create a bin folder to specify that this folder is PATH, then download the repo and give permissions

2. Synchronize the source code

mkdir Aosp
cd Aosp
//repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest
//指定版本
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-5.0.0_r1
repo sync

Normally, our above command is to create an Aosp folder and then synchronize the code directly after init initialization, but during our actual operation, we will encounter several small problems

  • a.repo sync no response

This may be a problem with the repo at the beginning of the curl repo, we can enter the bin directory

vim repo

See if there is any content in your repo script, if not, you need to refer to

git-repo help

Follow the above tips, first in your bin directory

//删除原先的无用repo
rm -rf repo
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
  • b. Unable to connect to source

It should be noted here that during the operation of the repo, it will try to access the official git source to update itself

write picture description here

If you want to use tuna's mirror source to update, you can copy the following content to your ~/.bashrc

export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'

Pay attention to restarting or refreshing the terminal so that we can continue init

write picture description here

At this point, we can repo sync to synchronize the source code.

Let me talk about it here, that is, some errors encountered during the sync process

write picture description here

this error:

error: Exited sync due to fetch errors

可以参考 When running repo sync error: Exited sync due to fetch errors

enter

repo sync -f -j8

can be solved

The second problem encountered

RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function

write picture description here

This is due to insufficient git default cache size, use the following command to increase the cache size

git config --global http.postBuffer 2000000000

The third problem encountered

Cannot fetch platform/packages/apps/OMA-DM

write picture description here

It is said that many people encountered this problem when they downloaded the source code of Android 5.0

my solution is

write picture description here

Comment out this line in the xml configuration file in the .repo directory

write picture description here

Finally, the long N hours have passed, and the AOSP source code of 5.0 has also been downloaded, but we still need to download one thing, that is the kernel

4. Download Kernel

We need to download the kernel separately, and each manufacturer is different, so there will be some differences. For details, please refer to this blog:

Download the Android kernel source code without going over the wall

I am using the tegra kernel of Google's own mobile phone

cd device/asus/grouper/
//查看记录
git log kernel
git clone https://aosp.tuna.tsinghua.edu.cn/kernel/tegra.git
cd tegra/
git checkout 5d8ecd2

5. Source code compilation

In fact, compiling is the highlight, because many problems will arise, we need to investigate step by step, first of all, let's look at the steps of compiling the source code

source build/envsetup.sh
//选择编译目标版本
lunch
//多线程编译
make -j8

Here I choose aosp_x86-eng

write picture description here

However, during the compilation process, there will be many problems. I did not compile it here, because I just looked at the source code, mainly to solve it one by one, and it is very troublesome to write it out, so I want to write a special article when I compile it next time. .

This article is written here first, and in the next article, we will learn about the Build environment

PS: Interested friends can join the group to discuss: 484167109

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325916419&siteId=291194637