Android Note: Application for download and compilation of CM9 source code

Source: Internet
Author: User
Tags java se

Recently, the company began to modify the framework based on android4.0 ICS. The company's mobile phone is not suitable for home testing and does not have the kernel permission.
From a personal perspective, I have two mobile phones, one is Htc G9 Aria, the other is Samsung I9100 Galaxys2, and the open source code of Cyanogenmod provides driver support for these mobile phones, it can also easily compile and package the package and install it on your mobile phone.
The previous article was about android2.3 compilation, which is outdated and has now upgraded ubuntu to 12.04, etc, I think it is very necessary to write a new blog to show how the latest android is compiled on the latest ubuntu.
Based on the above points, I will demonstrate how to compile the cm9 source code based on galaxys2 and package and zip it to your mobile phone.

1. Select ubuntu12.04
I used x64 for the first time and found many errors when configuring the environment. Later I used a 32-bit system and installed these necessary software without any errors, so here, if cyanogenmod ics source code is compiled using the 12.04 system, I recommend using a 32-bit system with my personal experience.

2. Memory and cpu
Some of my friends installed ubuntu on the virtual machine, so the memory allocation may be too small. We recommend that you try to increase the size as much as possible. During my 1 GB memory, I encountered an error during compilation, restart to set 2 GB memory.
If the cpu is too weak, the process may be killed during the compilation process. I used it once and restarted it. So pay attention to the cpu level.

3. java Selection
No matter the official android document or the article above, the installation of java will not be found, and their software source has problems. Manual installation is required.
But android ics compilation, the official article pointed out that support openjdk-6-jdk, so you can directly install openjdk6.
Note: Here I want to explain that the compilation script of CM9 ignores or handles some possible errors compared with the compilation script of the official source code, such as the java version check, if it is open jdk, the official compilation will fail, but it is actually the same. You only need to modify the script (build/core/main. mk) to find the java version:

Copy codeThe Code is as follows: # Check for the correct version of java
Java_version: = $ (shell java-version 2> & 1 | head-n 1 | grep '^ java. * ["] 1 \. 6 [\. "$] ')
Ifneq ($ (shell java-version 2> & 1 | grep-I openjdk ),)
Java_version: =
Endif
Ifeq ($ (strip $ (java_version )),)
$ (Info ************************************* ***********************)
$ (Info You are attempting to build with the incorrect version)
$ (Info of java .)
$ (Info $ (space ))
$ (Info Your version is: $ (shell java-version 2> & 1 | head-n 1 ).)
$ (Info The correct version is: Java SE 1.6 .)
$ (Info $ (space ))
$ (Info Please follow the machine setup instructions)
$ (Info $ (space) http://source.android.com/source/download.html)
$ (Info ************************************* ***********************)
# $ (Error stop) // if you are sure that jdk has been installed correctly, remove this sentence to continue compilation.
Endif

The compilation script of CM9 directly removes this sentence, but you should pay attention to installing the correct jdk version.

4. fixed the problem that Google source could not be accessed during the download process.
You need a vpn account.
The vpn I purchased earlier also has a free VPN. For details about the free VPN and VPN configuration, refer to the following two links:
Http: // 173.252.215.172/server/query
Http: // 173.252.215.172/setting/ubuntu.shtml
After configuring VPN, We can smoothly download all the CM9 source code from Ubuntu.

5. Environment Configuration
Refer to the official Ubuntu 12.04 (please note the official documentation to distinguish Ubutu11.10 x6 from the previous system). We need to configure the following environment:

Copy codeThe Code is as follows: sudo apt-get install git-core gnupg flex bison gperf build-essential
Sudo apt-get install zip curl libc6-dev libncurses5-dev: i386 x11proto-core-dev
Sudo apt-get install libx11-dev: i386 libreadline6-dev: i386 libgl1-mesa-dev: i386
Sudo apt-get install g ++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown
Sudo apt-get install libxml2-utils extends tproc zlib1g-dev: i386

There should be no problems.

6. Install repo

Copy codeThe Code is as follows: cd
Mkdir bin
Curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> ~ /Bin/repo
Chmod a + x ~ /Bin/repo
Alias repo = "~ /Bin/repo"

If we need to run the repo at any time, we 'd better configure the repo in the environment:Copy codeThe Code is as follows: vim ~ /. Bashrc
# After opening the file, add alias repo = "~ /Bin/repo ", save and exit
Source ~ /. Bashrc

In this user environment, you can repo wherever you are.

7. Download The CM9 source code
List Files are hosted on Github: https://github.com/CyanogenMod/android

Copy codeThe Code is as follows: mkdir cm9
Cd cm9
Repo init-u git: // github.com/CyanogenMod/android.git-B ics
Repo sync

The ics branch is the branch of CM9 ICS.
Wait for a while (if you are not prompted to open googlesource during the download process, remember to refer to the previous configuration of vpn firewall, I changed the host is invalid ).

8. Configure USB
This step is to copy the system property file from your mobile phone and compile the source code.
Ubuntu do not need to install a driver to connect to your phone, but need to configure, can refer to the official: http://source.android.com/source/initializing.html
Here I will also write down:

Copy codeThe Code is as follows: sudo vim/etc/udev/rules. d/51-android.rules

Then, add the following content:Copy codeThe Code is as follows: # Samsung
SUBSYSTEM = "usb", SYSFS {idVendor} = 04e8, MODE = 0666

This is the configuration of the Samsung mobile phone. Other mobile phones can view the corresponding id through the lsusb command. Add the above format to the/etc/udev/rules. d/51-android.rules file.
After the configuration, unplug the phone and plug it in. Basically, you can. If not, kill the-server first and connect it with the root user. If the problem persists, go to android-sdk/tools/and give your adb command file "chmod + s adb", kill-server, and adb. Try again several times.

9. Download a dedicated project for the device
CM9 is different from CM7 in downloading the device project. CM7 is automatically downloaded when the source code is downloaded. CM9 does not exist, but it can be manually intelligently recognized for downloading.
For example, if my mobile phone is galaxys2, run the following command:

Copy codeThe Code is as follows: brunch galaxys2

If the spelling is correct, it will automatically download the related projects of galaxys2 (in the directory ~ The following directory samsung/galaxys2 is added to/cm9/device ).

If the download is complete, stop compiling and proceed to the next step.

10. Get the mobile phone system property File

Copy codeThe Code is as follows: cd ~ /Cm9/device/samsung/galaxys2
/Extract-files.sh
Cd ~ /Cm9
Vendor/cm/get-prebuilts

This step only needs to be executed once.

11. Compile the CM9 source code
The source code of CM9 is much less error-prone than compiling the official Android source code.
First, initialize the variable:

Copy codeThe Code is as follows: cd cm9
Source build/envsetup. sh

Run the following command:Copy codeThe Code is as follows:Brunch galaxys2

Then wait!
If it is a virtual machine, the memory is tight and the cpu is insufficient, errors may occur at any time.
If an error occurs, analyze the cause of the error. It is still quite smooth here, interrupted once, and re-compiled again.
Ps: For official source code compilation, I believe there are always several errors, and CM9 is much better.
After compilation is complete, a zip file is generated, which can be flushed on your mobile phone.

12. compile the project
So far, we have set up a healthy CM9 environment, but our goal is not to compile the CM9 ROM, and this CM will generate a version of "nightly" every day, therefore, we mainly use this CM9 environment to compile frameworks, apps, and other projects.
For example, if we restart the system the next day, how does one compile framework-res.apk, framework.jar, and music.apk? We need to use this environment:

Copy codeThe Code is as follows: cd cm9
Source build/envsetup. sh
// Note the product name. When chooseproduct is used, add cm _ to galaxys2. Otherwise, the product cannot be found.
Chooseproduct cm_galaxys2
// Enter the framework/base/core/res.compile framework-res.apk
Cd framework/base/core/res
Mm
// You can also compile framework. jar.
Cd ~ /Cm9/framework/base/core/java
Mm
// You can compile music.apk.
Cd ~ /Cm9/packages/apps/Music
Mm

In this way, you can modify the system ROM and the system APP.

13. Summary
Building an Android environment and compiling the Android source code is a complex, time-consuming, and time-consuming process.
However, it is actually very easy to look back.

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.