(OK) Building Android from AOSP source code


[root@localhost android-6.0.1_r46]# cat /etc/redhat-release
Fedora release 23 (Twenty Three)

[root@localhost android-6.0.1_r46]# uname -a
Linux localhost.localdomain 4.4.8-300.fc23.x86_64 #1 SMP Wed Apr 20 16:59:27 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost android-6.0.1_r46]# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.5G        6.2G         54M        579M        1.2G        600M
Swap:          1.0G        1.0G          0B

[root@localhost android-6.0.1_r46]# cat /proc/cpuinfo
processor    : 3
vendor_id    : GenuineIntel
cpu family    : 6
model        : 60
model name    : Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
stepping    : 3
microcode    : 0x1e
cpu MHz        : 2153.906
cache size    : 3072 KB

+++++++++++++++++++++++++++++++++++++++++++++
download android source code
+++++++++++++++++++++++++++++++++++++++++++++
[root@localhost android-6.0.1_r46]# pwd
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46
[root@localhost android-6.0.1_r46]#

git config --global user.name "tongguang"
git config --global user.email "jsjoscpubupt@gmail.com"

repo init -u https://android.googlesource.com/platform/manifest

repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r1
repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r2
repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.2_r1
repo init -u https://android.googlesource.com/platform/manifest -b android-5.1.1_r37

repo init -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r46

repo sync


+++++++++++++++++++++++++++++++++++++++++++++

[root@localhost gem5-stable]# free
              total        used        free      shared  buff/cache   available
Mem:        7892744     4433200      222784      520468     3236760     2807120
Swap:       1028124     1028124           0
[root@localhost gem5-stable]# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.5G        4.2G        218M        508M        3.1G        2.7G
Swap:          1.0G        1.0G          0B
[root@localhost gem5-stable]#


[root@localhost android-6.0.1_r46]# pwd
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46
[root@localhost android-6.0.1_r46]# ls
Android.bp  bootstrap.bash  developers   external    libcore          out               prebuilts  tools
art         build           development  frameworks  libnativehelper  packages          sdk
bionic      cts             device       hardware    Makefile         pdk               system
bootable    dalvik          docs         kernel      ndk              platform_testing  toolchain
[root@localhost android-6.0.1_r46]#

java -Xmx5000M -Xms1500M -XshowSettings:all


++++++++++++++++++++++++++++++++++++++++
Establishing a Build Environment
++++++++++++++++++++++++++++++++++++++++

http://source.android.com/source/initializing.html

Put the following in your .bashrc (or equivalent):
export USE_CCACHE=1
export CCACHE_DIR=/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/ccache

-----------------------
In the root of the source tree, do the following:

[root@localhost android-6.0.1_r46]# pwd
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46
[root@localhost android-6.0.1_r46]# ls

export USE_CCACHE=1
export CCACHE_DIR=/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/ccache
prebuilts/misc/linux-x86/ccache/ccache -M 50G


The suggested cache size is 50-100G.
On Linux, you can watch ccache being used by doing the following:

watch -n1 -d prebuilts/misc/linux-x86/ccache/ccache -s
-----------------------

++++++++++++++++++++++++++++++++++++++++
building
++++++++++++++++++++++++++++++++++++++++
The suggested cache size is 50-100GB. You will need to run the following command once you have downloaded the source code:
prebuilts/misc/linux-x86/ccache/ccache -M 50G


. build/envsetup.sh
lunch aosp_arm-userdebug
make -j4


-----------------------
can ignore
-----------------------
find: “frameworks/base/docs/html-ndk”: 没有那个文件或目录
-----------------------

++++++++++++++++++++++++++++++++++++++++
need java-1.7.0-openjdk, not java-1.8.0-openjdk
++++++++++++++++++++++++++++++++++++++++

java -version

[root@localhost gem5-stable]# ls /usr/lib/jvm/
java                                           java-openjdk       jre-1.8.0-openjdk-1.8.0.91-6.b14.fc23.x86_64
java-1.8.0                                     jre                jre-openjdk
java-1.8.0-openjdk                             jre-1.8.0
java-1.8.0-openjdk-1.8.0.91-6.b14.fc23.x86_64  jre-1.8.0-openjdk
[root@localhost gem5-stable]#

============================================
Checking build tools versions...
************************************************************
You are attempting to build with the incorrect version
of java.
 
Your version is: openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode).
The required version is: "1.7.x"
 
Please follow the machine setup instructions at
    https://source.android.com/source/initializing.html
************************************************************
build/core/main.mk:171: *** stop。 停止。

#### make failed to build some targets (28 seconds) ####

[root@localhost android-6.0.1_r46]#
[root@localhost android-6.0.1_r46]# export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.x86_64
[root@localhost android-6.0.1_r46]# export PATH=$JAVA_HOME/bin:$PATH
[root@localhost android-6.0.1_r46]# java -version
java version "1.7.0_75"
OpenJDK Runtime Environment (fedora-2.5.4.2.fc20-x86_64 u75-b13)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)
[root@localhost android-6.0.1_r46]#

*********************************************************
install java-1.7.0-openjdk
*********************************************************
http://koji.fedoraproject.org/koji/buildinfo?buildID=605625

dnf search openjdk
dnf install java-atk-wrapper

[root@localhost 桌面]# ls java-1.7.0-openjdk-*
java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.x86_64.rpm
java-1.7.0-openjdk-accessibility-1.7.0.75-2.5.4.2.fc20.x86_64.rpm
java-1.7.0-openjdk-debuginfo-1.7.0.75-2.5.4.2.fc20.x86_64.rpm
java-1.7.0-openjdk-demo-1.7.0.75-2.5.4.2.fc20.x86_64.rpm
java-1.7.0-openjdk-devel-1.7.0.75-2.5.4.2.fc20.x86_64.rpm
java-1.7.0-openjdk-headless-1.7.0.75-2.5.4.2.fc20.x86_64.rpm
java-1.7.0-openjdk-src-1.7.0.75-2.5.4.2.fc20.x86_64.rpm

[root@localhost 桌面]# rpm -ivh --force --nodeps java-1.7.0-openjdk-*
[root@localhost 桌面]# java -version
[root@localhost 桌面]# ls /usr/lib/jvm/

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.x86_64
export PATH=$JAVA_HOME/bin:$PATH


*********************************************************
make -j4
*********************************************************
Install: out/host/linux-x86/lib64/libartd-compiler.so
java -Xmx3500m -jar out/host/linux-x86/framework/jill.jar  --output out/target/common/obj/JAVA_LIBRARIES/sdk_v8_intermediates/classes.jack.tmpjill.jack prebuilts/sdk/8/android.jar
java -Xmx3500m -jar out/host/linux-x86/framework/jill.jar  --output out/target/common/obj/JAVA_LIBRARIES/sdk_v9_intermediates/classes.jack.tmpjill.jack prebuilts/sdk/9/android.jar
java -Xmx3500m -jar out/host/linux-x86/framework/jill.jar  --output out/target/common/obj/JAVA_LIBRARIES/sdk_v4_intermediates/classes.jack.tmpjill.jack prebuilts/sdk/4/android.jar
java -Xmx3500m -jar out/host/linux-x86/framework/jill.jar  --output out/target/common/obj/JAVA_LIBRARIES/sdk_v20_intermediates/classes.jack.tmpjill.jack prebuilts/sdk/20/android.jar
java -Xmx3500m -jar out/host/linux-x86/framework/jill.jar  --output out/target/common/obj/JAVA_LIBRARIES/sdk_v19_intermediates/classes.jack.tmpjill.jack prebuilts/sdk/19/android.jar
make: fork: 无法分配内存
make: *** Deleting file 'out/target/common/obj/JAVA_LIBRARIES/sdk_v20_intermediates/classes.jack'

------------------------------------------
xkill, 关闭firefox,释放内存
------------------------------------------

*********************************************************

ERROR: Bad request, see Jack server log (/tmp/jack-root/jack-8072.log)
build/core/java.mk:643: recipe for target 'out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex' failed
make: *** [out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/with-local/classes.dex] Error 41
make: *** 正在等待未完成的任务....
DroidDoc took 26 sec. to write docs to out/target/common/docs/system-api-stubs
DroidDoc took 27 sec. to write docs to out/target/common/docs/api-stubs

#### make failed to build some targets (02:09:42 (hh:mm:ss)) ####

------------------------------------------
it is OK to exe "make -j4" again
------------------------------------------

Creating filesystem with parameters:
    Size: 1610612736
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 6144
    Label: system
    Blocks: 393216
    Block groups: 12
    Reserved block group size: 95
Created filesystem with 1653/98304 inodes and 136658/393216 blocks
Install system fs image: out/target/product/generic/system.img
out/target/product/generic/system.img+ maxsize=1644333504 blocksize=2112 total=1610612736 reserve=16610880

#### make completed successfully (45:33 (mm:ss)) ####

[root@localhost android-6.0.1_r46]#

#### make completed successfully (02:09:42 (hh:mm:ss)) + (45:33 (mm:ss)) = (02:55:15 (hh:mm:ss)) ####

------------------------------------------
So far, build android successfully.
------------------------------------------

*********************************************************

[root@localhost android-6.0.1_r46]# cd out/target/product/generic/
[root@localhost generic]# pwd
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46/out/target/product/generic

[root@localhost generic]# du -hs *
4.0K    android-info.txt
4.0K    cache
5.1M    cache.img
72K    clean_steps.mk
424K    data
66M    dex_bootjars
113M    gen
68K    installed-files.txt
10G    obj
4.0K    previous_build_config.mk
880K    ramdisk.img
708K    recovery
1.6M    root
1.7G    symbols
484M    system
1.6G    system.img
11M    userdata.img

[root@localhost generic]# ls -p
android-info.txt  clean_steps.mk  gen/                 previous_build_config.mk  root/     system.img
cache/            data/           installed-files.txt  ramdisk.img               symbols/  userdata.img
cache.img         dex_bootjars/   obj/                 recovery/                 system/

[root@localhost generic]#  emulator

emulator: WARNING: system partition size adjusted to match image file (1536 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: 7
Created filesystem with 11/4224 inodes and 1302/16896 blocks

----------
or execute the following commands.
----------
[root@localhost android-6.0.1_r46]# pwd
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46
[root@localhost android-6.0.1_r46]# emulator -sysdir out/target/product/generic -system system.img

++++++++++++++++++++++++++++++++++++++++
So far, all is OK
++++++++++++++++++++++++++++++++++++++++


++++++++++++++++++++++++++++++++++++++++
example: alter the name of the application Messaging
++++++++++++++++++++++++++++++++++++++++
[root@localhost android-6.0.1_r46]# gedit packages/apps/Messaging/res/values/strings.xml

    <!-- The name of the application as it appears under the main Launcher icon and in various activity titles -->
    <string name="app_name">Messaging-ztg</string>

[root@localhost android-6.0.1_r46]# cd packages/apps/Messaging
[root@localhost Messaging]# pwd
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46/packages/apps/Messaging
[root@localhost Messaging]# ls
AndroidManifest.xml  assets  ForceProguard.mk  proguard.flags          proguard-test.flags  src    tools
Android.mk           build   jni               proguard-release.flags  res                  tests  version.mk

[root@localhost Messaging]# mm
Install: out/target/product/generic/data/app/messagingtests/messagingtests.apk
make: Leaving directory '/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46'

#### make completed successfully (01:30 (mm:ss)) ####

[root@localhost Messaging]#

[root@localhost android-6.0.1_r46]# adb shell
root@generic:/ # mount -o remount,rw /system

[root@localhost android-6.0.1_r46]#
adb push out/target/product/generic/data/app/messagingtests/messagingtests.apk system/app/messaging/messaging.apk

++++++++++++++++++++++

[root@localhost Messaging]# cd -
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android/android-6.0.1_r46
[root@localhost android-6.0.1_r46]# tree out/target/product/generic/system/priv-app/MmsService/
out/target/product/generic/system/priv-app/MmsService/
├── MmsService.apk
└── oat
    └── arm
        └── MmsService.odex

2 directories, 2 files

[root@localhost android-6.0.1_r46]# emulator -sysdir out/target/product/generic -system system.img

[root@localhost android-6.0.1_r46]# adb shell
root@generic:/ # mount -o remount,rw /system

root@generic:/ # df
Filesystem               Size     Used     Free   Blksize
/dev                   243.4M    68.0K   243.3M   4096
/sys/fs/cgroup         243.4M    12.0K   243.4M   4096
/mnt                   243.4M     0.0K   243.4M   4096
/system                  1.5G   509.7M  1002.2M   4096
/data                  541.3M    81.1M   460.2M   4096
/cache                  65.0M     4.1M    60.9M   4096
/storage               243.4M     0.0K   243.4M   4096


[root@localhost android-6.0.1_r46]#
adb push out/target/product/generic/system/priv-app/MmsService/MmsService.apk system/priv-app/MmsService/
adb push out/target/product/generic/system/priv-app/MmsService/oat/arm/MmsService.odex system/priv-app/MmsService/oat/arm

[root@localhost android-6.0.1_r46]# emulator -sysdir out/target/product/generic -system system.img

++++++++++++++++++++++++++++++++++++++++
So far, example is not OK
++++++++++++++++++++++++++++++++++++++++




http://gem5.org/Android_KitKat

[root@localhost android]# pwd
/run/media/root/158a840e-63fa-4544-b0b8-dc0d40c79241/android
[root@localhost android]#

dd if=/dev/zero of=myimage.img bs=1M count=2048
losetup /dev/loop0 myimage.img
fdisk /dev/loop0
--------------------
Part.No Usage     Approximate Size
1     /     500MB
2     /data     1GB
3     /cache     500MB
--------------------

partprobe /dev/loop0
mkfs.ext4 -L AndroidRoot /dev/loop0p1
mkfs.ext4 -L AndroidData /dev/loop0p2
mkfs.ext4 -L AndroidCache /dev/loop0p3

mkdir -p /mnt/android
mount /dev/loop0p1 /mnt/android
cd /mnt/android
zcat AOSP/out/target/product/generic/ramdisk.img  | cpio -i
mkdir cache

mkdir -p /mnt/tmp
mount -oro,loop AOSP/out/target/product/generic/system.img /mnt/tmp
cp -a /mnt/tmp/* system/

umount /mnt/android
losetup -d /dev/loop0

++++++++++++++++++++++++++++++++++++++++


++++++++++++++++++++++++++++++++++++++++

posted @ 2016-06-11 08:39  张同光  阅读(229)  评论(0编辑  收藏  举报