Android practice: Android 5.1.1 source code compilation and writing,

Source: Internet
Author: User

Android practice: Android 5.1.1 source code compilation and writing,

Most of the friends who bought Nexus mobile phones tried to modify their own systems. In addition to their high cost effectiveness, they are still very popular among developers. I upgraded my 5 prince to the 6.0 preview version, and I was reluctant to switch back to the 5.1 era. However, as there are still some days before the 6.0 source code release, the 5.1 source code compilation and writing are still mainstream, and the entire process is recorded below (we have to be patient for a long time ).

Build a Development Environment

Ubuntu 14.04 recommended
1. openjdk is needed

$ sudo apt-get update$ sudo apt-get install openjdk-7-jdk

Set it the default java version

$ sudo update-alternatives --config java$ sudo update-alternatives --config javac

2. required package

sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip

Problems:

$ sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip[sudo] password for linc: Reading package lists... DoneBuilding dependency tree       Reading state information... Donemake is already the newest version.zip is already the newest version.git is already the newest version.git set to manually installed.libxml2-utils is already the newest version.libxml2-utils set to manually installed.Some packages could not be installed. This may mean that you haverequested an impossible situation or if you are using the unstabledistribution that some required packages have not yet been createdor been moved out of Incoming.The following information may help to resolve the situation:The following packages have unmet dependencies: g++-multilib : Depends: gcc-multilib (>= 4:4.8.2-1ubuntu6) but it is not going to be installedE: Unable to correct problems, you have held broken packages

Follow these steps:

$ sudo apt-get install g++-multilib$ sudo apt-get install  bison git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip
Gcc is required
$ sudo apt-get install gcc$ gcc -vThread model: posixgcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04) 
Repo
$ mkdir ~/bin$ PATH=~/bin:$PATH$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo$ chmod a+x ~/bin/repo

Check sh1 sum:

$ sha1sum repo b8bd1804f432ecf1bab730949c82b93b0fc5fede  repo

For version 1.21, the SHA-1 checksum for repo is b8bd1804f432ecf1bab730949c82b93b0fc5fede

Repo init

The initialization for Nexus5 5.1.1 is as follows:

LMY48I  android-5.1.1_r9    Lollipop    Nexus 4, Nexus 5, Nexus 6, Nexus 7 (flo), Nexus 9 (volantis/volantisg), Nexus 10
$ repo init -u https://android.googlesource.com/platform/manifest -b android-5.1.1_r9Your identity is: linc <xxx@xxx.com>If you want to change this, please re-run 'repo init' with --config-nameTesting colorized output (for 'repo diff', 'repo status'):  black    red      green    yellow   blue     magenta   cyan     white   bold     dim      ul       reverse repo has been initialized in /home/linc/source-android/android-source
Repo sync
$ repo sync

Two days a night, the download was completed, and the code reached 34 GB.

Setting up ccache

Put the following in your. bashrc (or equivalent ):

export USE_CCACHE=1

Run the command:

prebuilts/misc/linux-x86/ccache/ccache -M 50G
Building the System

1. Set up environment

$ source build/envsetup.sh

Or

$ . build/envsetup.sh

2. Choose a Target

$ lunch You're building on LinuxLunch menu... pick a combo:     1. aosp_arm-eng     2. aosp_arm64-eng     3. aosp_mips-eng     4. aosp_mips64-eng     5. aosp_x86-eng     6. aosp_x86_64-eng     7. aosp_manta-userdebug     8. aosp_flo-userdebug     9. aosp_deb-userdebug     10. full_fugu-userdebug     11. aosp_fugu-userdebug     12. aosp_tilapia-userdebug     13. aosp_grouper-userdebug     14. aosp_mako-userdebug     15. aosp_hammerhead-userdebug     16. aosp_flounder-userdebug     17. aosp_shamu-userdebug     18. mini_emulator_x86-userdebug     19. mini_emulator_arm64-userdebug     20. mini_emulator_x86_64-userdebug     21. mini_emulator_mips-userdebug     22. m_e_arm-userdebugWhich would you like? [aosp_arm-eng] 

Nexus5 selects 15. If it is used only for simulators, select 1.
3. build

make -j4

If an error occurs while waiting for other tasks to be completed, it is a multi-thread conflict.
4. error
1)

No private recovery resources for TARGET_DEVICE hammerheadhost C++: bcc <= frameworks/compile/libbcc/tools/bcc/Main.cppclang++: error: unable to execute command: Executable "as" doesn't exist!clang++: error: assembler command failed with exit code 1 (use -v to see invocation)make: *** [out/host/linux-x86/obj32/EXECUTABLES/bcc_intermediates/Main.o] Error 1

Try make clean. This is the consequence of not installing gcc.

Build successfully
#### make completed successfully (05:53:54 (hh:mm:ss)) ####

The directory structure is as follows:

out/target/product/hammerhead$ du -sh *4.0K    android-info.txt8.8M    boot.img4.0K    cache14M cache.img64K clean_steps.mk172K    data4.0K    fake_packages81M gen64K installed-files.txt8.1M    kernel16G obj4.0K    previous_build_config.mk700K    ramdisk.img1.4M    ramdisk-recovery.img2.2M    recovery9.5M    recovery.img1.3M    root2.9G    symbols288M    system307M    system.img135M    userdata.img
Flash device

To flash a device, you will need to use fastboot, which shocould be written ded in your path after a successful build. place the device in fastboot mode either manually by holding the appropriate key combination at boot, or from the shell

$ adb reboot bootloader

Once the device is in fastboot mode, run

$ fastboot flashall -w

The-w option wipes the/data partition on the device; this is useful for your first time flashing a special device but is otherwise unnecessary.

For more information about building for and running on actual hardware, see Running Builds.

Flash emulator

1. build generic img
Lunch 1 and make normally.

Make completed successfully (05:02:47 (hh: mm: ss ))

2. Start the simulator

~/source-android/android-source/out/target/product/generic$ emulator -sysdir ~/source-android/android-source/out/target/product/generic -system system.img emulator: WARNING: system partition size adjusted to match image file (550 MB > 200 MB)emulator: WARNING: data partition size adjusted to match image file (550 MB > 200 MB)Creating filesystem with parameters:    Size: 69206016    Block size: 4096    Blocks per group: 32768    Inodes per group: 4224    Inode size: 256    Journal blocks: 1024    Label:     Blocks: 16896    Block groups: 1    Reserved block group size: 7Created filesystem with 11/4224 inodes and 1302/16896 blocks

The simulator starts smoothly. There are many differences with the real machine, such as the boot screen, Home UI and control are different. Please wait for the specific reason.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.