Ubuntu 14.04 編譯 Android 4.2.2 for Tiny4412


.

.

.

.

.

在學校里是用 Redhat 6.4 編譯的 Android 4.2.2 很順利,把源碼包拷貝到筆記本上的 Ubuntu 14.04 上再編譯遭遇了各種坑,所以便有了這篇博客記錄解決每一個坑的過程。所幸這些坑解決起來還不算復雜,稍微 Google 一下就找到了解決方案。

 

1.首先是安裝 JDK 和 arm-linux-gcc 工具鏈,這兩步只是解壓縮之后配置環境變量就行了,所以這里就不再贅述了。
 注意 JDK 必須采用 1.6 版本的,據說 android 4.x 都需要使用標准的 JDK 1.6 編譯,也就是說 OpenJDK 是不行的,必須用 Sun 的 JDK,這一點我沒有親測過。

2.安裝 gperf,我這里用的是 3.0.4,采用源碼編譯安裝。

[yuhuashi@local android]$ tar xvzf gperf-3.0.4.tar.gz
[yuhuashi@local android]$ cd gperf-3.0.4/
[yuhuashi@local gperf-3.0.4]$ ./configure
[yuhuashi@local gperf-3.0.4]$ make -j4
[yuhuashi@local gperf-3.0.4]$ make install
[yuhuashi@local android]$ man gperf

OK,如果沒有報錯的話,那么恭喜你第二步成功了。

3.接下來便進入正題了,開始編譯 android 源碼,版本是 4.4.2。

因為是在 Tiny4412 開發板上運行,所以代碼包可能被修改過,具體有沒有被修改過我也不知道,因為還沒有研究過 android 移植,暫時先把步驟記錄下來。

[yuhuashi@local android]$ tar xvf android-4.2.2_r1-fs-20140526.tar.gz
[yuhuashi@local android]$ cd android-4.2.2_r1/

設置環境變量

[yuhuashi@local android-4.2.2_r1]$ source setenv

選擇編譯適用的平台

[yuhuashi@local android-4.2.2_r1]$ lunch

發現出現了一串"無法找到 bison 命令"的錯誤提示,於是安裝 bison

[yuhuashi@local android-4.2.2_r1]$ sudo apt-get install bison

注意 千萬不要手賤把 bison++ 也裝上了,否則編譯的時候會出現一個 double free 的錯誤!

接下來要開始編譯了:    ====前方高能預警,請無關人員立即撤離,關閉所有非必要運行的程序,並確保散熱器正常工作!!!====

[yuhuashi@local android-4.2.2_r1]$ make -j4

過程中出現了 Switch.pm 的錯誤,具體的錯誤信息沒有記錄下來,如果各位也遇到了同樣的錯誤,make 會自動停止,所以只寫一下解決的方法吧。

其實只需要安裝一下 perl 的 switch 庫即可:

sudo apt-get install libswitch-perl

安裝好 switch 庫后重新 make -j4 繼續編譯。

過了一會兒出現了一個這樣的錯誤:

byteswap.h:22:3: error: #error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead.

解決辦法是安裝 GCC 的 multilib 庫,然后 make -j4 繼續編譯。

sudo apt-get install gcc-multilib

OK,所有的坑都解決了,經過將近2個小時的高速運轉之后終於見到了如下提示:

Creating filesystem with parameters:
Size: 685768704
Block size: 4096
Blocks per group: 32768
Inodes per group: 6976
Inode size: 256
Journal blocks: 2616
Label:
Blocks: 167424
Block groups: 6
Reserved block group size: 47
Created filesystem with 1104/41856 inodes and 52043/167424 blocks
+ '[' 0 -ne 0 ']'
Running: simg2img out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/system.img out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/unsparse_system.img
Running: e2fsck -f -n out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/unsparse_system.img
e2fsck 1.41.14 (22-Dec-2010)

Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
out/target/product/tiny4412/obj/PACKAGING/systemimage_intermediates/unsparse_system.img: 1104/41856 files (0.0% non-contiguous), 52043/167424 blocks
Install system fs image: out/target/product/tiny4412/system.img
out/target/product/tiny4412/system.img+ maxsize=700123776 blocksize=4224 total=203674048 reserve=7075200

如果你也看到了類似的提示消息,恭喜你成功了!

編譯的結果在out文件夾下。

4.接下來生成刷機需要的 img 鏡像文件

不過這需要依賴 UBoot 的一個工具:mkimage,如果你之前編譯過 UBoot,可以在 UBoot 的 tools 目錄下找到這個程序,也可以通過 apt-get 來安裝它:

[yuhuashi@local android-4.2.2_r1]$ sudo apt-get install u-boot-tools

有了這個工具我們便可以制作 img 鏡像文件了

[yuhuashi@local android-4.2.2_r1]$ ./gen-img.sh

OK,看看是不是在當前目錄下出現了下面這幾個文件:

[yuhuashi@local android-4.2.2_r1]$ ls
system.img
userdata-16g.img
userdata-4g.img
userdata-8g.img
userdata.img
ramdisk-u.img
......
隱藏了若干不相關文件

如果出現了這幾個文件,那么說明刷機必要的鏡像文件我們已經有了,恭喜你,還差一個內核就可以在開發板上燒寫系統了。

現在只是編譯了 android 本身,內核還沒有編譯,明天繼續記錄編譯內核的過程。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM