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目录解决。

你可能感兴趣的:(Android源码编译教程)