2014年10月8日 星期三

Android Compile on Ubuntu (整理中


此篇目的是為了編譯一個 Android source code,
過程中有遇到許多問題,全部都整理在最底部 Debug 區。

一、下載 Android Open Source 

1. 建立一個 Ubuntu-12.04_amd64 環境

下例為 QEMU 虛擬機跑 Ubuntu ,可參考:
安裝 QEMU 虛擬機
建立一個 arm.img 並且可以用虛擬機開機

Ubuntu Official: http://www.ubuntu.com/
Download: ubuntu-12.04.5-desktop-amd64.iso

開啟虛擬機:
qemu-img create ubuntuOS.img 80G

qemu-system-x86_64 -enable-kvm \
-cpu host \
-smp 4 \
-m 4000 \
-hda ubuntuOS.img \
-boot c 
-net nic \
-net bridge,br=br9 &

開始 Ubuntu 安裝…

2. 虛擬機連上網路:

本例使用 Bridge ,可以參考文章 Bridge 建立橋接網路
來讓虛擬機連上網際網路!
之後就可以透過 ssh 連線自己的虛擬機比較方便工作。

### 後面都是虛擬機環境下 ###

3. 下載 Android source code準備

下載 AOSP (Android Open Source Project),
需要準備幾個工具:curlgitpython
sudo apt-get update && apt-get install curl git python

### 接下來後面都用一般 User 權限 ###

4. 設定版本控制系統工具 git 

(於一般User 權限下) 
假設我的使用者帳號:myUser
假設我的 e-mail:myMail@gmail.com
git config --global user.name myUser
git config --global user.email myMail@gmail.com

5. 下載 repo 管理工具

(repo 是 Google所發展出來的工具, 適用於Android之初始化)
(於一般User 權限下)
mkdir ~/bin
echo 'export PATH=$PATH:~/bin' >> ~/.bashrc
source ~/.bashrc

curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

chmod u+x ~/bin/repo


6. repo 設定初始化

(於一般User 權限下)
mkdir ~/android_src ; cd ~/android_src
repo init -u https://android.googlesource.com/platform/manifest

後面的過程中,會出現問題(y/n),只要跟著預設選就行。

7. 開始下載 Source Code 

(需要漫長等待時間!容量近30GB)

cd ~/android_src
repo sync -j核心數


二、Android 核心編譯

1. 裝編譯相關套件
sudo apt-get update && apt-get install libglapi-mesa:i386 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 gcc-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386

2. 安裝 Open JDK 7
sudo apt-get update && apt-get install openjdk-7-jdk

(於一般User 權限下)
加到可執行路徑:
echo 'export PATH=$PATH:/usr/lib/jvm/java-7-openjdk-amd64/bin' >> ~/.bashrc
source ~/.bashrc

3. 安裝 Java SE 6 JDK
(於一般User 權限下)
Oracle載點:Java SE Development Kit 6u45 ,
記得勾選「Accept License Agreement 」,可能需要會員,
 Ubuntu-12.04_amd64 下,這邊要載 jdk-6u45-linux-x64.bin
chmod u+x ./jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
sudo mv jdk1.6.0_45 /opt

加到可執行路徑:
echo 'export PATH=$PATH:/opt/jdk1.6.0_45/bin' >> ~/.bashrc
source ~/.bashrc

4. 下載 Prebuilt Binaries
要去找自己所使用的手機或硬體廠商所推出的驅動或 Binaries,本例所要編的硬體為 Cubieboard 1 (A10核心)

Web Site:Cubieboard Android 4.0.x Release
Download:Livesuit Program Linux(64bit)

下載會得到一個「LiveSuitV306_For_Linux64.zip」,接著:
unzip LiveSuitV306_For_Linux64.zip
cp LiveSuit_For_Linux64/LiveSuit.run ~/android-src/
cd ~/android-src/
chmod u+x LiveSuit.run
./LiveSuit.run

5. 開始編譯
設定環境參數
cd ~/android
source ~/android/build/envsetup.sh

開始編譯
lunch full-eng
make -j核心數

如果成功會看到下面訊息:


6. 模擬器開啟 Android
./out/host/linux-x86/bin/emulator








<pre class="codeblock prettyprint"></pre>






Debug1.
進入 Ubuntu 進行套件更新時出現:
GPG error: http://www.debian-multimedia.org etch Release: The following signatures couldn't be verified because teh public key is not available: NO_PUBKEY 123456789123456789
Sol 1:
APT 套件安裝管理

Debug2. 
若 apt-get install 安裝時出現訊息:
dpkg: error: configuration error: /etc/dpkg/dpkg.cfg.d/multiarch:1: unknown option 'foreign-architecture
Sol 2:
sudo rm /etc/dpkg/dpkg.cfg.d/multiarch


Debug3.
安裝「編譯相關套件」時,若出現:
E: Unable to locate package mingw32
E: Package 'python-markdown' has no installation candidate
Sol 3:
sudo vim /etc/apt/sources.list

找到鏡像站設定:
deb http://archive.ubuntu.com/ubuntu precise main
在 main 後面加上 universe

Debug4.
執行 ./LiveSuit.run 出現:
<pre class="codeblock prettyprint">Selecting previously unselected package awdev-dkms.
(Reading database ... 153279 files and directories currently installed.)
Unpacking awdev-dkms (from /tmp/awdev-dkms_0.5_all.deb) ...
dpkg: dependency problems prevent configuration of awdev-dkms:
 awdev-dkms depends on dkms (>= 1.95); however:
  Package dkms is not installed.
dpkg: error processing awdev-dkms (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
awdev-dkms</pre>
Sol 4:
<pre class="codeblock prettyprint">sudo apt-get install awdev-dkms</pre>

Debug5.
進行 make ARCH=arm menuconfig,出現:
<pre class="codeblock prettyprint">[scripts/kconfig/mconf] Error</pre>

Sol 5:
<pre class="codeblock prettyprint">sudo apt-get install lib32ncurses5-dev</pre>

Debug 6.
當執行編譯指AT "make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage modules -j核心數",出現:
<pre class="codeblock prettyprint">make: arm-none-linux-gnueabi-gcc: Command not found
/bin/sh: 1: arm-none-linux-gnueabi-gcc: not found
make[2]: *** [scripts/mod/empty.o] Error 127
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [scripts/mod] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [scripts] Error 2</pre>

Sol 6:
FriendlyARM下載 arm-toolchain

Debug7.
執行「./build.sh -p sun4i_crane -k 3.0」,出現:
[arch/arm/boot/uImage] Error

Sol 7:
sudo apt-get install u-boot-tools

Debug8.
執行「./build.sh -p sun4i_crane -k 3.0」,出現:
[dhd_linux.o] Error 1
[dhd-cdc-sdmmc-gpl] Error 2

Sol 8:
$ 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

如果還是不行:
1. rm -r /home/user/a10_android/cb-A10/lichee/linux-3.0/modules/wifi/bcm40181/5.90.125.69.2/open-src/src/dhd/linux/dhd-cdc-sdmmc-gpl-3.0.8"
2. rm -r /home/user/a10_android/cb-A10/linux-3.0/modules/wifi/bcm40183/5.90.125.95.3/open-src/src/dhd/linux/dhd-cdc-sdmmc-gpl-3.0.8"

最後解決:
rm -r /home/user/a10_android/cb-A10/lichee/linux-3.0/modules/wifi/usi-bcm4329/v4.218.248.15/open-src/src/dhd/linux/dhd-cdc-sdmmc-gpl-3.0.8

Debug 9.
執行 make -j 4時:
dalvik/CleanSpec.mk:47: * missing separator. Stop.
#### make failed to build some targets (5 seconds) ####

Sol 9:
重開 Terminal,重新執行
source build/envsetup.sh
lunch
選11 apollo_cubieboard-eng
make -j8

Debug10.
執行 make -j4時:
Checking build tools versions...
******************************************************
You are attempting to build with the incorrect version
of java.

Your version is: java version "1.7.0_65".
The correct version is: Java SE 1.6.

Please follow the machine setup instructions at
    http://source.android.com/source/download.html
******************************************************
build/core/main.mk:131: *** stop.  Stop.

Sol 10:
1. java -version 出現「java version "1.6.0_45"」是正確的,
如果不對,就改 ~/.bashrc,加入以下:
export PATH=$PATH:/opt/jdk1.6.0_45/bin

重新載入 ~/.bashrc :
source ~/.bashrc

2. 先做 sudo update-alternatives --config java
以我的為例出現「There is only one alternative in link group java: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java」,代表現在的系統預設沒設對,操作如下(記得ROOT):
sudo update-alternatives --install /usr/bin/java java /opt/jdk1.6.0_45/bin/java 300

sudo update-alternatives --config java
設定預設為「/opt/jdk1.6.0_45/bin/java」

同上,javac 也要改
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.6.0_45/bin/javac 300

sudo update-alternatives --config javac
設定預設為「/opt/jdk1.6.0_45/bin/javac」

Debug11.
執行 make -j 4時,出現一堆:
error: unmappable character for encoding ASCII

Sol:

Debug12.
執行 make -j 4時,
[out/target/common/docs/api-stubs-timestamp] Error

Sol:



Debug12.
執行 make -j 4時,
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
make: *** Waiting for unfinished jobs....

Sol:



Debug13.
執行 time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4,出現:
arm-linux-gnueabi-ld: final link failed: No space left on device
make: *** [.tmp_vmlinux1] Error 1

sol:
硬磁空間不足,清出空間。

Debug14.
執行 time make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- uImage -j 4,出現:
drivers/built-in.o: In function `static_key_false':
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_start'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_start'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_erase_end'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_start'
/home/user/linux-sunxi/include/linux/jump_label.h:157: undefined reference to `__tracepoint_mmc_blk_rw_start'
make: *** [.tmp_vmlinux1] Error 1

sol 14:
http://linux-sunxi.org/FirstSteps#Building_the_kernel


Debug 15.
執行 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig 出現:
collect2: ld returned 1 exit status
make[1]: *** [scripts/kconfig/mconf] Error 1
make: *** [menuconfig] Error 2


Sol 15.
apt-get install libncurses5-dev

Debug 16. 
android 下執行 make 出現:
make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1

Sol 16.
sudo apt-get install lib32ncurses5-dev












Reference:
http://weiwei.pixnet.net/blog/post/31481109-%E7%B7%A8%E8%AD%AFandroid-source-code-%E9%8C%AF%E8%AA%A4%E8%A7%A3%E6%B1%BA%E8%BE%A6%E6%B3%95

https://github.com/crossfire77/Android_Toolchains

http://blog.logan.tw/2011/10/android-open-source-project-android.html

http://blog.logan.tw/2013/09/build-android-aosp.html


Android Official Website:
https://source.android.com/compatibility/downloads.html

Cubieboard Official:
http://cubieboard.org/download/

Cubieboard Open Source:
https://github.com/cubieboard

CC-A80-kernel-source:
https://github.com/cubieboard/CC-A80-kernel-source

http://cubian.org/sources/

http://dywang.csie.cyut.edu.tw/moodle23/dywang/clanguage/node106.html

http://dl.cubieboard.org/software/a10-cubieboard/android/

http://docs.cubieboard.org/tutorials/cb1/installation/building_android_ics_a10_image

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

http://persevere.iteye.com/blog/1479524

http://code.google.com/p/metadata-extractor/issues/detail?id=90

http://blog.csdn.net/zeng622peng/article/details/6837250

http://cheng-min-i-taiwan.blogspot.tw/2012/05/ubuntu-1204-64bit-android-ics.html

http://bbs.chinaunix.net/thread-2121093-1-1.html

https://github.com/linux-sunxi/linux-sunxi/issues/150

http://linux-sunxi.org/Toolchain

http://linux-sunxi.org/FirstSteps#Building_the_kernel

http://linux-sunxi.org/Linux_Kernel#A10

沒有留言:

張貼留言