閱讀425 返回首頁    go 阿裏雲 go 技術社區[雲棲]


android4.1.1係統編譯全過程

一、編譯環境:
首先介紹編譯中使用的工具:
虛擬機:    vmare 9 下載地址:https://blog.csdn.net/hudan2714/article/details/7902654
linux平台:ubuntu 12.04 64位
jdk:              sun-java6-jdk (64位)
交叉編譯工具鏈:gcc 使用的版本是:4.6.3 

想要完成最終的編譯,當然首要的就是檢查環境:
1、安裝的ubuntu設置空間大小:至少需要30G
     目前下載的包就有10G:有圖有真相:
       
       包括解壓編譯後大小有30G了:
     
      所以空間一定要夠了才行。

2、gcc和g++不能使用使用4.4版本了(編譯android4.0係統使用的是4.4),
                       現在隻要使用係統自帶的4.6.3(ubuntu12.04) 就可以了。
      

3、jdk版本:sun-java6-jdk
       


二、編譯:
        編譯過程不知道,可以查看官方文檔了。這裏做簡單說明:
        1.source build/envsetup.sh   這是向係統導入不同的廠商版本,並添加m命令。
        2.lunch 選擇編譯廠商版本。
        3.mm    編譯版本

         還是看圖說話吧:
           

            當然這裏的lunch full-eng是編譯所有,如果嫌慢,就單獨編譯某一個也可。
             

              再mm就可以編譯了(必須要source了,才有mm命令,而且隻在此terminal有效)
               


三、編譯中遇到的錯誤:
       錯誤太多,做了一些總結,有點亂,如果編譯過程中遇到錯誤,可以來查看:
/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

make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Error 127
解決方法: sudo apt-get install flex

make: *** [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/css/CSSPropertyNames.h] Error 25
解決方法:sudo apt-get install gperf

/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directoryIn file included from /home/hudan/android/source/android4.1.1/prebuilts/gcc/linux-x86/host/i686-linux-glibc2.7-4.6/bin/../sysroot/usr/include/sys/types.h:27:0,
                 from frameworks/native/include/utils/Errors.h:20,
                 from frameworks/native/include/utils/String8.h:20,
                 from cts/suite/audio_quality/lib/include/Settings.h:21,
                 from cts/suite/audio_quality/lib/src/Settings.cpp:17:
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directoryIn file included from /usr/include/stdlib.h:25:0,
                 from cts/suite/audio_quality/lib/src/Adb.cpp:16:
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory

compilation terminated.
compilation terminated.

compilation terminated.
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libcts_audio_quality_intermediates/src/SimpleScriptExec.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libcts_audio_quality_intermediates/src/Adb.o] Error 1
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libcts_audio_quality_intermediates/src/Settings.o] Error 1
In file included from /usr/include/semaphore.h:22:0,
                 from cts/suite/audio_quality/lib/include/Semaphore.h:21,
                 from cts/suite/audio_quality/lib/src/Semaphore.cpp:17:
/usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
compilation terminated.
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libcts_audio_quality_intermediates/src/Semaphore.o] Error 
解決方法:sudo apt-get install gcc-multilib 


error libGL.so: cannot open shared object file: No such file or directory
OSError: libGL.so: cannot open shared object file: No such file or directory

may appear on Linux systems when you try to launch VNL for the first time. To solve it, create (as administrator) a new link in /usr/lib:

sudo ln -s /usr/lib/libGL.so.1.2 /usr/lib/libGL.so

If you have a 64-bit Linux, use /usr/lib64 instead.

First check that you actually have "libGL.so.1.2" in /usr/lib or /usr/lib64; it might be called "libGL.so.1" or something else instead, or located in another directory, depending on the video drivers. You can use

locate libGL

to find the correct file to link to.

而我使用的是ubuntu 12.04 bit-64位,在/usr/lib/並沒有libGL.so文件。

可以使用locate libGL查找此文件。結果:


找出了這麼多,當然是選擇64位平台下的libGL了。



但是針對這幾個,不知道要選擇哪一個好,還請高手指點。


Failed to load libGL.so

error libGL.so: wrong ELF class: ELFCLASS64

linux係統是64位的,這個命令不支持64位

最佳解決方案,把oralce-lib環境變量設置為lib32即可


最後選擇ln還36位

代碼:hudan@ubuntu:~/android/source/android4.1.1/out$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1.2 /usr/lib/libGL.so


再運行編譯好的system.img,出現如下的錯誤:


直接參數-ramdisk ramdisk.img去掉,結果模擬器跑起來了,但不能把內核啟動起來。


no ABI error , when creating an Android virtual device



E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)

E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

解決:sudo rm /var/lib/apt/lists/lock


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


n file included from /usr/include/stdlib.h:25,
                 from build/tools/acp/acp.c:11:
/usr/include/features.h:323: 致命錯誤: bits/predefs.h:沒有那個文件或目錄編譯中斷。
make: *** [out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp.o] 錯誤 1

make: *** [out/host/linux-86/obj/STATIC_LIBRARIES/libcts_audio_quality_intermediates/src/Adb.o] Error 1

安裝:libc6-dev-i386
     sudo apt-get install libc6-dev-i386


make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/libwebcore_intermediates/LINKED/libwebcore.so] Error 1

make: *** Waiting for unfinished jobs....

make: *** [out/target/common/obj/APPS/android.core.tests.libcore.package.dalvik.no-core-tests-res_intermediates/noproguard.classes-with-local.dex] Error 130

上次make或或者mmm的時候生成一些錯誤的東西

可以使用:make clean 再重新make

解決:rm out/target/common/obj/APPS/ -r (如果還是有這樣的錯誤,就隻能clean了)


四、運行編譯好的係統
vi /etc/profile
增加以下三句
最終運行配置,給大家截個圖:

隻需要這三句就OK

配置完,source /etc/profile 要是出現黑屏,建議重啟一下。接下:

運行時隻要:emulator


完美運行:



下麵是遇到的問題,可以看看:

編譯完係統後,用模擬器運行係統,在2.3之前隻需要配置:
export ANDROID_PRODUCT_OUT=/home/hudan/android/source/android4.1.1/out/target/product/generic_x86
export PATH=$PATH:/home/hudan/android/source/android4.1.1/out/host/linux-x86/bin
但這樣配置就一直出現如下的錯誤:
emulator: ERROR: You did not specify a virtual device name, and the system
directory could not be found.

If you are an Android SDK user, please use '@<name>' or '-avd <name>'
to start a given virtual device (see -help-avd for details).

Otherwise, follow the instructions in -help-disk-images to start the emulator

這就是adnroid4.1.1下emulator不能直接運行的問題 
參考:https://blog.csdn.net/dongminghao888/article/details/7860884
最後配置export ANDROID_BUILD_TOP=/home/hudan/android/source/android4.1.1
一切就都OK了。



如果是研究android源碼的歡迎加群交流:android係統高級交流群:247039470

轉載請附原文地址:https://blog.csdn.net/hudan2714/article/details/7926924






最後更新:2017-04-02 16:48:17

  上一篇:go 什麼是開放的雲計算?
  下一篇:go 手機核戰爭,一觸即發