Android 原始碼編譯make的錯誤處理
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
Android原始碼下載:官方下載 或參考android原始碼下載方式
Android編譯版本: PLATFORM_VERSION=4.0.1(最新Android 4.0.1)
OS 作業系統平臺: Linux yanggang 2.6.35-30-generic #61-Ubuntu SMP Tue Oct 11 15:29:15 UTC 2011 i686 GNU/Linux(Ubuntu10.10 32bit)
首先,我們先安裝一些常用的工具
curl: sudo apt-get install curl
git: sudo apt-get install git
g++: sudo apt-get install g++
然後,make遇到缺什麼就安裝什麼
/usr/bin/ld: cannot find -lz
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld: cannot find -lz
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1
解決方法: sudo apt-get install zlib1g-dev
/bin/bash: bison: command not found
Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y
bison -d -o out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp frameworks/base/tools/aidl/aidl_language_y.y
/bin/bash: bison: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error 127
解決方法:sudo apt-get install bison
/bin/bash: flex: command not found
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp: In function ‘int yyparse()’:
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:1827: warning: deprecated conversion from string constant to ‘char*’
out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp:1970: warning: deprecated conversion from string constant to ‘char*’
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
/bin/bash: flex: command not found
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 127
解決方法: sudo apt-get install flex
/usr/bin/ld: cannot find -lncurses
host Executable: adb (out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb)
/usr/bin/ld: cannot find -lncurses
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/adb_intermediates/adb] Error 1
解決方法:sudo apt-get install libncurses5-dev
fatal error: GL/glx.h: No such file or directory
development/tools/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp:22: fatal error: GL/glx.h: No such file or directory
compilation terminated.
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libGLcommon_intermediates/GLDispatch.o] Error 1
解決方法:sudo apt-get install libgl1-mesa-dev
sh: gperf: not found
target Generated: libwebcore <= external/webkit/Source/JavaScriptCore/create_regex_tables
Generating CSSPropertyNames.h <= CSSPropertyNames.in
sh: gperf: not found
calling gperf failed: 32512 at ./makeprop.pl line 140.
make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/css/CSSPropertyNames.h] Error 25
make: *** Deleting file `out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/css/CSSPropertyNames.h'
解決方法:sudo apt-get install gperf
上述安裝,可以用一條命令完成:
sudo apt-get install git-core 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 openjdk-6-jdk 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
詳見:
Initializing a Build Environment(android)
make編譯原始碼的錯誤處理:
當前Java版本高於指定版本或不是規範的Java JDK(如OpenJDK),輸入“java -version”檢視JDK版本:
從上圖發現,的確是由前面一鍵安裝時安裝了 openjdk-6-jdk,有兩種方式可以解決:
1) 配置規範的Java SDK
解壓: ./jdk-6u20-linux-i586.bin
拷貝: mv jdk1.6.0_20 /home/homer/eclipse/
配置: sudo vi /etc/profile
export JAVA_HOME=/home/homer/eclipse/jdk1.6.0_20
export JRE_HOME=/home/homer/eclipse/jdk1.6.0_20/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
檢視驗證,如下圖:
2) 解除安裝openjdk,重新安裝jdk
a)解除安裝openjdk
點選左上角“ubuntu“的logo, 輸入 “ubuntu software center”,查詢軟體中心管理
然後,選擇“Installed”, 輸入“openjdk”, 查詢已安裝的 openjdk,如下圖:
選擇“Remove”,解除安裝openjdk
b)重新安裝jdk
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"$ sudo apt-get update$ sudo apt-get install sun-java6-jdk
其實,除了上述兩種解決方法外,如果當前JDK版本是規範的JDK 1.6以上(如:jdk1.7.0_05,我預設用的jdk版本),也會報錯說不是正確的版本。
仔細分析Makefile檔案,發現其依賴關係如下:
Makefile —> build/core/main.mk —> 進行了jdk的版本判斷, 指令碼程式碼如下圖:
從上圖,分析程式碼,不難看出“openjdk“ 和 “jdk1.7.0_05” 版本編譯不通過的原因了吧。。。。
(1) 如果“java -version” 中包含了“openjdk”,則 “$(shell java -version 2>&1 | grep -i openjdk)” 過濾的“openjdk”不會為空,自然其與空不等,即ifneq條件成立,因此執行“java_version :=" 設定為空
(2) 如果是(1)情況,java_version為空, 自然輸出錯誤提示資訊; 如果“java -version”包含了“jdk1.7.0_05”而不是“xx1.6xx“字樣,第一行過濾出來的java_version也是為空,結果也輸出錯誤提示資訊。
找出了問題,那該又如何解決呢? 知道了原理,問題就簡單了(如果你和我一樣使用的是“jdk1.7.0_05“及以上的1.7版本)
修改 '^java .*[ "]1\.6[\. "$$]' 為 '^java .*[ "]1\.7[\. "$$]'
最後,編譯Android原始碼:
make -j4
參考推薦:
Android Source Download(google)
Android Source Building(google)
Initializing a Build Environment(google)