Android源碼編譯教程

前言

當前環境:

1、Ubuntu16.04,已經安裝好了各種依賴

2、Android代碼版本,android-9.0.0_r3

一、導入環境

源碼根目錄輸入:

source build/envsetup.sh

輸出:

including device/generic/car/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-mips64/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/uml/vendorsetup.sh
including device/google/cuttlefish/vendorsetup.sh
including device/google/marlin/vendorsetup.sh
including device/google/muskie/vendorsetup.sh
including device/google/taimen/vendorsetup.sh
including device/linaro/hikey/vendorsetup.sh
including sdk/bash_completion/adb.bash

二、配置編譯信息

輸入:

lunch

輸入可以選擇的版本

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. aosp_car_arm-userdebug
     8. aosp_car_arm64-userdebug
     9. aosp_car_x86-userdebug
     10. aosp_car_x86_64-userdebug
     11. mini_emulator_arm64-userdebug
     12. m_e_arm-userdebug
     13. m_e_mips64-eng
     14. m_e_mips-userdebug
     15. mini_emulator_x86_64-userdebug
     16. mini_emulator_x86-userdebug
     17. uml-userdebug
     18. aosp_cf_x86_auto-userdebug
     19. aosp_cf_x86_phone-userdebug
     20. aosp_cf_x86_tablet-userdebug
     21. aosp_cf_x86_tablet_3g-userdebug
     22. aosp_cf_x86_tv-userdebug
     23. aosp_cf_x86_wear-userdebug
     24. aosp_cf_x86_64_auto-userdebug
     25. aosp_cf_x86_64_phone-userdebug
     26. aosp_cf_x86_64_tablet-userdebug
     27. aosp_cf_x86_64_tablet_3g-userdebug
     28. aosp_cf_x86_64_tv-userdebug
     29. aosp_cf_x86_64_wear-userdebug
     30. cf_x86_auto-userdebug
     31. cf_x86_phone-userdebug
     32. cf_x86_tablet-userdebug
     33. cf_x86_tablet_3g-userdebug
     34. cf_x86_tv-userdebug
     35. cf_x86_wear-userdebug
     36. cf_x86_64_auto-userdebug
     37. cf_x86_64_phone-userdebug
     38. cf_x86_64_tablet-userdebug
     39. cf_x86_64_tablet_3g-userdebug
     40. cf_x86_64_tv-userdebug
     41. cf_x86_64_wear-userdebug
     42. aosp_marlin-userdebug
     43. aosp_marlin_svelte-userdebug
     44. aosp_sailfish-userdebug
     45. aosp_walleye-userdebug
     46. aosp_walleye_test-userdebug
     47. aosp_taimen-userdebug
     48. hikey-userdebug
     49. hikey64_only-userdebug
     50. hikey960-userdebug

Which would you like? [aosp_arm-eng] #這裏輸入對應數字並回車

爲了方便可以用一下方式,以aosp_arm64-eng爲例:

lunch aosp_arm64-eng
# 或者
lunch 2

三、編譯代碼

輸入:

make -j4
# -j4是用4個核心數同時編譯的意思,可不加,也可以根據機器實際改變數字

在不出錯的情況下,漫長的等待,出現下面情況表示編譯成功

#### build completed successfully (01:23:12 (hh:mm:ss)) ####

四、啓動Android虛擬機

在編譯成功後,根目錄輸入:

emulator

啓動成功

啓動成功

五、錯誤記錄

錯誤一

[1/1] out/soong/.minibootstrap/minibp out/soong/.bootstrap/build.ninja
FAILED: out/soong/.bootstrap/build.ninja 
out/soong/.minibootstrap/minibp -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/.bootstrap/build.ninja.d -o out/soong/.bootstrap/build.ninja Android.bp
internal error: could not open symlink hardware/qcom/sm8150/Android.bp; its target (data/ipacfg-mgr/os_pickup.bp) cannot be opened
internal error: could not open symlink hardware/qcom/sdm845/Android.bp; its target (data/ipacfg-mgr/os_pickup.bp) cannot be opened
ninja: build stopped: subcommand failed.
11:02:14 soong minibootstrap failed with: exit status 1

#### failed to build some targets (13 seconds)

解:查了一下,對應兩個bp文件都是空的,直接刪除解決。

錯誤二

[1/1] out/soong/.minibootstrap/minibp out/soong/.bootstrap/build.ninja
[55/56] glob prebuilts/ndk/stl.bp
[77/77] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
out/build-aosp_arm64-cleanspec.ninja is missing, regenerating...
out/build-aosp_arm64.ninja is missing, regenerating...
[382/936] including hardware/qcom/sdm845/Android.mk ...
hardware/qcom/power/Android.mk:3: error: hardware/qcom/sdm845/Android.mk: No such file or directory
11:10:31 ckati failed with: exit status 1

#### failed to build some targets (01:19 (mm:ss))

解:查了一下sdm845目錄下只有一個空的mk,刪除sdm845目錄解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章