Compile the Android source code in Linux and modify the debugging system.

Source: Internet
Author: User
The following content is a summary after reading a lot of articles and a lot of attempts, as well as notes that may be repeated in the future. links are added to the referenced content. welcome to the discussion. first, download and compile the Android source code, which requires you to install Linux.


The following content is a summary after reading a lot of articles and a lot of attempts, as well as notes that may be repeated in the future.
Links are added to the referenced content. You are welcome to discuss them.

First, download and compile the Android source code. This requires you to install Linux. I use Ubuntu 11.04,
If Ubuntu is installed on a virtual machine, I only need 1 GB of memory, and I feel that it is enough. unlike what I said on the Internet, I need at least 1.5 GB of memory,
Because I only have 2 GB of memory, if I allocate 1.5 to the virtual machine, it will be completely inactive.

In addition, the entire process is executed under root. if it is not root, we recommend that you use sudo-sH to perform all the following operations.
Although the official 64-bit operating system is required for compilation, but I use 32-bit, how to modify it will be described below.
Another problem is that it only occurs when compiled with a specific Ubuntu 11.04 version. I don't know if the source code of the new version has been fixed,
For details about how to obtain the source code repo, tutorials are everywhere on the Internet, so I won't mention it. it's okay to strictly follow the official tutorials.
In addition, you can use multiple threads to download the repo with the "-j number" parameter.

Note that many tutorials also say that you must use JDK 1.6 to compile the source code and to compile the SDK,
In fact, it is no longer needed, the latest version of Android as long as the direct installation of sun-java6-jdk is good. (apt-get can not find it to update your source or directly go to the official website)

If you are using a 32-bit Linux, you must make the following changes before compiling:

Set
./External/clearsilver/cgi/Android. mk
./External/clearsilver/java-jni/Android. mk
./External/clearsilver/util/Android. mk
./External/clearsilver/cs/Android. mk

Of the four files
LOCAL_CFLAGS + =-m64
LOCAL_LDFLAGS + =-m64
Comment out, or replace "64" with "32"
LOCAL_CFLAGS + =-m32
LOCAL_LDFLAGS + =-m32

Then
In./build/core/main. mk
Ifneq (64, $ (findstring 64, $ (build_arch )))
Changed:
Ifneq (i686, $ (findstring i686, $ (build_arch )))

After the above modifications, you can start to compile the source code, cd to the root directory of the source code, and press "make". then you can check the movie ..
In this step, three files with the suffix img will be produced under android/out/target/product/generic/. we recommend that you copy the files,
I have encountered a situation where the files are inexplicably lost and the results need to be re-made.

If you just need to modify and compile and test the system app, you do not need to make the sdk.

Before work, you need to configure the environment variables:

Gedit ~ /. Modify bashrc to the source code path and add the following two lines to the end of the file:

Export PATH = $ PATH:/home/xxx/android/out/host/linux-x86/bin
Export ANDROID_PRODUCT_OUT =/home/xxx/android/out/target/product/generic

Remember to execute
Source ~ /. Bashrc

Run the following command in the source code root directory:

. Build/envsetup. sh
It will help you enable several new commands, such as the "mmm"

Then you can modify the system app you want to modify, all under android/packages.
I will write another article for the specific modification example. let's talk about the entire process first.
For example, I modified the system's English input method, which is located in android/packages
After modification, run the command directly in the android Directory. specify the directory containing the Android. mk file:

Mmm packages/imputmethods/LatinIME/
Compilation will be completed soon
(Do not directly execute "mmm" without adding any parameters in the root directory, otherwise you will regret it. this is equivalent to "make" that took a long time ")

Then you need to install the compiled file into the simulator. you can start the simulator before, or you can start it now,
You do not need to restart the simulator before and after the installation. you can directly see the effect by running the adb install command.

To start the simulator, run the following command in android/out/target/product/generic:

Emulator-image system. img-data userdata. img-ramdisk. img
Then use this command to pass the compiled apk file to the simulator:

Adb install-r/home/xxx/android/out/target/product/generic/system/app/***. apk
Here, we can basically implement the entire process of modifying and debugging the system app,
In fact, the previous environment configuration work is always done once and for all. In fact, the two commands mmm and adb install-r are used all the time.

Because some system apps involve jni, it is wrong to view the project under Eclipse, and I do not know how to implement normal debugging in Eclipse,
Therefore, you can only directly modify it in the text editor and then install it to the simulator to view the effect.

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.