1、編譯環境
ubuntu 14.04 64位 (必須64位)
gcc 4.8.4
硬盤容量: 100G +
內存:8G
安裝ubuntu後,換源,使用國內163源
sudo apt-get update //更新源
sudo apt-get upgrade //更新系統,會自動更新到gcc 4.8.4
2、安裝編譯環境 jdk ,所需的是open jdk 1.8
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config java
sudo update-alternatives–-config javac
3、下載android 7.0 源碼
(1)使用已有的包(部分源碼 23.1G,我所使用的)
創建一個文件夾Android,將已有源碼拷貝到文件夾下解壓
mkdir Android
tar -xvf repo.tar.gz解壓之後,會在本文件中生成一個 .repo 的隱藏文件(使用ll命令可以查看隱藏文件)
此時,需要進行同步,將完整的android源碼同步下來,使用repo sync 進行同步,不過此時repo 工具還沒有安裝,安裝repo 工具
mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
上面過程中,會提示沒有curl 工具,還要安裝curl:
sudo apt-get install curl
同步源代碼:
安裝完成後,執行pepo sync 命令:
$repo sync
此時,出現錯誤
Error:Gitconfig: [Errno 2] No such file or directory
原因:應該是沒有安裝git
解決辦法:
sudo apt-get install git
sudo apt-get install git-core
再次運行repo sync
運行不久後再次出現錯誤:
Fetching projects: 98% (502/512)
error: Exited sync due to fetch errors
解決辦法:重新運行repo sync可以的到解決,直到同步完成
(2)源碼包完全網上下載(沒做)
初始化repo$ mkdir Android
$ cd Android
repo初始化
$ repo init -u git://android.git.kernel.org/platform/manifest.git
在此過程中需要輸入名字和email地址。初始化成功後,會顯示:
repo initialized in /android
在~/Android下會有一個.repo的隱藏目錄(使用ll 命令可以查看隱藏文件)。
同步源代碼
$ repo sync
4、編譯源碼
增加ccahe 的大小(在當前編譯目錄下執行命令)
export USE_CCACHE=1
export CCACHE_DIR=.ccache
prebuilts/misc/linux-x86/ccache/ccache -M 50G
$source build/envsetup.sh
$lunch
$make -j4
編譯過程中的錯誤提示:
錯誤1:
flex-2.5.39: fatal internal error, exec of /usr/bin/m4 failed
解決辦法:安裝bison (語法分析生成器)
sodu apt-get install bison
錯誤2:
/bin/bash: xmllint: command not found
解決辦法:
sudo apt-get install libxml2-utils
錯誤3:
/bin/sh: 1: lzop: not found
解決辦法:
sudo apt-get install lzop
錯誤4:
FAILED: /bin/bash out/target/common/obj/JAVA_LIBRARIES/core-all_intermediates/with-local/classes.dex.rsp
Java heap space
Try increasing heap size with java option '-Xmx<size>'
Warning: This may have produced partial or corrupted output.
ninja: build stopped: subcommand failed.
build/core/ninja.mk:146: recipe for target 'ninja_wrapper' failed
make: *** [ninja_wrapper] Error 1
\#### make failed to build some targets (05:44 (mm:ss)) ####
解決辦法:---配置heap size 大小
$:export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
$:out/host/linux-x86/bin/jack-admin kill-server
$:out/host/linux-x86/bin/jack-admin start-server
錯誤5:
Internal compiler error (version 1.3-b8 'Douarn' (395600 eb49254e63b960b5a42dd28dcb1d46f28496395d by [email protected])).
Warning: This may have produced partial or corrupted output.
[ 82% 32919/39701] Building with Jack:...sr166-tests_intermediates/classes.jack
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] Error 1
#### make failed to build some targets (04:33:35 (hh:mm:ss)) ####
編譯器內部錯誤:我是重新編譯了一次。
編譯結束:
Creating filesystem with parameters:
Journal blocks: 7168
Label: system
Blocks: 458752
Block groups: 14
Reserved block group size: 111
Created filesystem with 1961/114688 inodes and 164035/458752 blocks
[100% 31172/31172] Install system fs i... out/target/product/generic/system.img
out/target/product/generic/system.img+ maxsize=1918388736 blocksize=2112 total=1879048192 reserve=19379712