Android Learning Series (38)-download and compile the Android source code

Source: Internet
Author: User

The previous articles have introduced how to download and compile the Android or CM source code, but they are always in the extended series.
With the deepening of learning, the android source code is of great reference and learning value. We strongly recommend that you download, compile, and learn it. Therefore, we will introduce it to the basic chapter of the Learning Series.
I just installed UBUNTU14.04, so I tried to compile the android source code in the new environment.
For the sake of harmony, I bought a temporary VPN, recommended (still stable): http://a.wy002.com/34750

1. Reference Link (official ):
Http://source.android.com/source/initializing.html Environment
Download: http://source.android.com/source/downloading.html
Compile: http://source.android.com/source/building-running.html

2. Ubuntu14.04 (x64) + OpenJDK7
The latest code can be compiled using the default openjdk7, but cannot be compiled using jdk6.
Install openjdk7:

$ sudo apt-get update$ sudo apt-get install openjdk-7-jdk$ sudo update-alternatives --config java$ sudo update-alternatives --config javac

Install other components:

$ sudo apt-get install git gnupg flex bison gperf build-essential \  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \  libgl1-mesa-dev g++-multilib mingw32 tofrodos \  python-markdown libxml2-utils xsltproc zlib1g-dev:i386$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

I installed it quickly here (I configured mirror 163), and everything went smoothly.

3. Connect to VPN
For more information, see the VPN official instructions:
Https://www.51jsq.org/setting/ubuntu.shtml

4. Install repo

$ mkdir ~/bin$ PATH=~/bin:$PATH$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo$ chmod a+x ~/bin/repo

For convenience, you can continue to configure the repo:
Add the following in. bashrc:

alias repo='~/bin/repo'

5. Start download

$ Mkdir android $ cd android $ repo init-u https://android.googlesource.com/platform/manifest // Download latest

The above is the initialization (init) repo version library, the real download:

$ repo sync

Maybe it was my life. After the wall was turned over, the download went smoothly. There were not many problems that I had previously encountered with the Internet. The only embarrassing problem was that the download process was often interrupted.
When I woke up in the morning, I broke it. I continued to repo sync. When I came back from work, I saw it. I broke it. repo sync...
It took about two days and two nights to work overtime this evening to download the package.
Please note that if an error occurs during downloading, please take a closer look at the error. It's not just a repo sync. This time I am so smooth and it's "unscientific "~
Download Now !!!!

6. Start Compilation
Initialize some parameters and variables:

$ source build/envsetup.sh

Define the device type, we use the simulator (aosp_arm-eng ):

/* Xxx @ ubuntu :~ /Data/android $ 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. vbox_x86-eng 8. aosp_hammerhead-userdebug 9. aosp_mako-userdebug 10. aosp_manta-userdebug 11. aosp_tilapia-userdebug 12. aosp_grouper-userdebug 13. aosp_deb-userdebug10, summary 14. aosp_flo-userdebug 15. mini_armv7a_neon-user Debug 16. mini_mips-userdebug 17. mini_x86-userdebugWhich wowould you like? [Aosp_arm-eng] 1 ========================================== ========== RELPLATFORM_VERSION = feature _ PRODUCT = feature = engTARGET_BUILD_TYPE = feature = TARGET_ARCH = feature = TARGET_ARCH_VARIANT = armv7-aTARGET_CPU_VARIANT = genericHOST_ARCH = x86HOST_ OS = feature = Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trustyHOST_BUILD_TYPE = releaseBUILD_ID = OPENMASTEROUT_DIR = out ====================================== ======= */

After the definition is complete, start compiling (the latest version 4.4.3 ):

/*xxx@ubuntu:~/Data/android$ make -j8============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=4.4.3.2.1.000.000TARGET_PRODUCT=aosp_armTARGET_BUILD_VARIANT=engTARGET_BUILD_TYPE=releaseTARGET_BUILD_APPS=TARGET_ARCH=armTARGET_2ND_ARCH=TARGET_ARCH_VARIANT=armv7-aTARGET_CPU_VARIANT=genericHOST_ARCH=x86HOST_OS=linuxHOST_OS_EXTRA=Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14.04-trustyHOST_BUILD_TYPE=releaseBUILD_ID=OPENMASTEROUT_DIR=out============================================including ./abi/cpp/Android.mk ...including ./art/Android.mk ...including ./bionic/Android.mk ...including ./bootable/diskinstaller/Android.mk ...including ./bootable/recovery/Android.mk ...including ./build/libs/host/Android.mk ...including ./build/target/board/Android.mk ...including ./build/tools/Android.mk ...including ./cts/Android.mk ...// ... ...Installed file list: out/target/product/generic/installed-files.txtTarget system fs image: out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.imgRunning:  mkuserimg.sh out/target/product/generic/system out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img ext4 system 576716800 out/target/product/generic/root/file_contexts// ... ...+ ENABLE_SPARSE_IMAGE=+ '[' out/target/product/generic/system = -s ']'+ '[' 6 -ne 5 -a 6 -ne 6 ']'+ SRC_DIR=out/target/product/generic/system+ '[' '!' -d out/target/product/generic/system ']'+ OUTPUT_FILE=out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img+ EXT_VARIANT=ext4+ MOUNT_POINT=system+ SIZE=576716800+ FC=out/target/product/generic/root/file_contexts+ case $EXT_VARIANT in+ '[' -z system ']'+ '[' -z 576716800 ']'+ '[' -n out/target/product/generic/root/file_contexts ']'+ FCOPT='-S out/target/product/generic/root/file_contexts'+ MAKE_EXT4FS_CMD='make_ext4fs  -S out/target/product/generic/root/file_contexts -l 576716800 -a system out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/generic/system'+ echo make_ext4fs -S out/target/product/generic/root/file_contexts -l 576716800 -a system out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/generic/systemmake_ext4fs -S out/target/product/generic/root/file_contexts -l 576716800 -a system out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/generic/system+ make_ext4fs -S out/target/product/generic/root/file_contexts -l 576716800 -a system out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/generic/systemCreating filesystem with parameters:    Size: 576716800    Block size: 4096    Blocks per group: 32768    Inodes per group: 7040    Inode size: 256    Journal blocks: 2200    Label:     Blocks: 140800    Block groups: 5    Reserved block group size: 39Created filesystem with 1295/35200 inodes and 100299/140800 blocks+ '[' 0 -ne 0 ']'Install system fs image: out/target/product/generic/system.imgout/target/product/generic/system.img+ maxsize=588791808 blocksize=2112 total=576716800 reserve=5947392*/

Compilation completed.

7. Run the simulator
Added in souce build/envsetup. sh.Emulator command:

$ emulator

You can start a simulator:

8. Modify and compile the system application code
Let's Modify the title of the system application Mms:

Compile with the mm command:

/* Xxx @ ubuntu :~ /Data/android/packages/apps/Mms $ mm ============================ ====================== RELPLATFORM_VERSION = 4.4.3.2.1.000.000TARGET _ PRODUCT = metric = engTARGET_BUILD_TYPE = metric = TARGET_ARCH = metric = TARGET_ARCH_VARIANT = armv7-aTARGET_CPU_VARIANT = genericHOST_ARCH = x86HOST_ OS = linuxHOST_ OS _EXTRA = Linux-3.13.0-24-generic-x86_64-with-Ubuntu-14. 04-trustyHOST_BUILD_TYPE = releaseBUILD_ID = OPENMASTEROUT_DIR = out ======================== ============ make: go to the '/home/xxx/Data/android' target R. java/Manifest. java: Mms (out/target/common/obj/APPS/Mms_intermediates/src/R. stamp) warning: string 'menu _ insert_smiley 'has no default translation.tar get Java: Mms (out/target/common/obj/APPS/Mms_intermediates/classes) Note: some input files use or overwrite outdated APIs. Note: For details, use-Xlint: deprecation to re-compile. Note: Some input files use uninspected or insecure operations. Note: For details, use-Xlint: unchecked to recompile. Copying: out/target/common/obj/APPS/Mms_intermediates/classes-jarjar.jarCopying: out/target/common/obj/APPS/Mms_intermediates/emma_out/lib/classes-jarjar.jarCopying: out/target/common/obj/APPS/Mms_intermediates/classes. jarProguard: out/target/common/obj/APPS/Mms_intermediates/proguard. classes. jarProGuard, version 4.10 Reading program jar [/home/xxx/Data/android/out/target/common/obj/APPS/Mms_intermediates/classes. jar] //... ...tar get Dex: MmsCopying: out/target/common/obj/APPS/Mms_intermediates/classes. dextarget Package: Mms (out/target/product/generic/obj/APPS/Mms_intermediates/package.apk) nothing matches overlay file ic_contact_picture.png, for flavor, mdpi, libpng warning: iCCP: known incorrect sRGB profilelibpng warning: iCCP: known incorrect sRGB profilewarning: string 'menu _ insert_smiley 'has no default translation. warning: string 'menu _ insert_smiley 'is missing 19 required localizations: az_AZ en_AU en_CA en_GB en_IN en_NZ en_SG en_US eo_EU hy_AM ka_GE km_KH lo_LA mn_MN ne_NP si_LK zh_CN zh_HK 1_ I 21424 21424 art/dex2oat/dex2oat. HTTP: 1082] dex2oat: out/host/linux-x86/bin/dex2oatd -- runtime-arg-Xms64m -- runtime-arg-Xmx64m -- boot-image = out/target/product/generic/dex_bootjars/system/framework/ boot. art -- dex-file = out/target/product/generic/obj/APPS/Mms_intermediates/package.apk -- dex-location =/system/priv-app/Mms.apk -- oat-file = out /target/product/generic/obj/APPS/Mms_intermediates/package. odex -- android-root = out/target/product/generic/system -- instruction-set = arm -- instruction-set-features = defaultdex2oatd I 21424 21424 art/dex2oat/dex2oat. HTTP: 252] dex2oat took 1.189425041 s (threads: 8) Notice file: packages/apps/Mms/NOTICE -- out/target/product/generic/obj/NOTICE_FILES/src/system/priv-app/Mms.apk.txt Install: out/target/product/generic/system/priv-app/Mms.apk Install: out/target/product/generic/system/priv-app/Mms. odex //...... install: out/target/product/generic/data/app/MmsTests.apk Install: out/target/product/generic/data/app/MmsTests. odexmake: Leave the directory "/home/xxx/Data/android "*/

Two files are generated:
Out/target/product/generic/system/priv-app/Mms.apk
Out/target/product/generic/system/priv-app/Mms. odex

9. install it on your mobile phone
Because it is a system application, in order to restart effectively, use the push command to push the two files to the corresponding location in the simulator:

// Note that the current core applications are changed from the previous system/app to the system/priv-app. Do not push the error/* xxx @ ubuntu :~ /Data/android $ adb push out/target/product/generic/system/priv-app/Mms. odex system/priv-app2893 KB/s (2085348 bytes in 0.703 s) xxx @ ubuntu :~ /Data/android $ adb push out/target/product/generic/system/priv-app/Mms.apk system/priv-app3315 KB/s (1785258 bytes in 0.525 s )*/

Check the simulator effect:

The title is replaced.
Similarly, you can modify the framework and replace the kernel. However, some of them need to restart the simulator and some need to re-compile the relevant modules. Here is a brief introduction and I will discuss it later.

10. Summary
With the source code, you can learn excellent code. You can refer to the history submission to see how they are improved. You can customize your own system styles and do a lot of things...

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.