Android 源码下载 & 编译全过程

近日网速还算可以,于是乎决定下载一下Android源代码以供在家研究学习。下载之前先认识一下repo,整个Android源码是由很多个git项目构成,Google对Android代码的更新也是更新到相应模块的git项目上。那对于需要编译Android的开发者来说,要分别clone 每个git项目而且还要放到固定的位置确实是件惨绝人寰的w事,所以Google就开发了一个基于Python编写的帮助开发者管理多个项目的工具,这个工具就叫repo,说白了repo就是封装了git命令的python脚本。

知道repo之后就下来就来研究一下怎么把Android源码弄下来,下载Android通常有两种方式,一种是直接用repo命令,直接了当,但是问题是需要浪费很长的时间,具体操作如下

  • 下载repo

            Google的repo下载比较麻烦,需要翻墙。建议用清华源上提供的,点击查看。

  • repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-cts-7.0_r22
  • repo sync -j6  -f (这个过程经常中断,要多执行几次才可以)

第二种Android源码的方式是先下载个初始包,然后在执行repo sync进行代码同步即可

  • wget -c -t 0 https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar
  • tar -xvf aosp-latest.tar
  • repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-cts-7.0_r22
  • repo sync

无论以上那种方式获取Android代码都是一个非常耗时的过程,建议在临睡觉前进行代码同步,等第二天醒来就差不多同步完成了。

获取完代码之后接下来就是紧张又刺激的编译环节

  1. 首先进入Android源码目录,进行如下操作
ll@ll-pc:~/android/aosp$ source build/envsetup.sh 
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/google/dragon/vendorsetup.sh
including device/google/marlin/vendorsetup.sh
including device/huawei/angler/vendorsetup.sh
including device/lge/bullhead/vendorsetup.sh
including device/linaro/hikey/vendorsetup.sh
including sdk/bash_completion/adb.bash
ll@ll-pc:~/android/aosp$ 
ll@ll-pc:~/android/aosp$ 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. mini_emulator_arm64-userdebug
     8. m_e_arm-userdebug
     9. mini_emulator_x86_64-userdebug
     10. mini_emulator_x86-userdebug
     11. aosp_dragon-userdebug
     12. aosp_dragon-eng
     13. aosp_marlin-userdebug
     14. aosp_sailfish-userdebug
     15. aosp_angler-userdebug
     16. aosp_bullhead-userdebug
     17. hikey-userdebug

Which would you like? [aosp_arm-eng] 9

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.1
TARGET_PRODUCT=mini_emulator_x86_64
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_CPU_VARIANT=
TARGET_2ND_ARCH=x86
TARGET_2ND_ARCH_VARIANT=x86
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.13.0-45-generic-x86_64-with-Ubuntu-16.04-xenial
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=N9F27M
OUT_DIR=out
============================================
ll@ll-pc:~/android/aosp$ 

ll@ll-pc:~/android/aosp$ make -j8

接下来就是漫长的等待过程,上面执行lunch之后的选项是针对不同平台的,根据实际情况去选择,我这里选择了9,make -j8 中的8 是指线程的数量,就是要用几个线程去编译,通常是cpu核心的2倍。


Android编译过程会遇到各式各样的问题,不同的主机也会出现不同的问题,这时就需要我们沉着面对、冷静思考,多搜搜资料问题肯定会被解决的。下面是我这次编译过程所遇到的问题

  1. including ./art/Android.mk ...
    build/core/java.mk:26: *** art/tools/amm: Invalid LOCAL_SDK_VERSION 'current' Choices are: test_current .
    build/core/ninja.mk:163: recipe for target 'out/build-mini_emulator_x86_64.ninja' failed
    make: *** [out/build-mini_emulator_x86_64.ninja] Error 1
    
    解决方法:由于本人的疏忽大意,没有对manifest.xml 进行初始化,而是直接使用的是master分支上的manifest.xml,repo sync之后使用repo forall -c git checkut  android-7.1.1_r22强制切换的分支,导致源码不完整或者源码各模块版本不一致,从而导致了这个问题,解决办法是在repo sync 之前先执行 repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-cts-7.0_r22,然后再repo sync,这个问题就解决了。
  2. [  0% 8/27631] host C: libcrypto-host_32 <= external/boringssl/src/crypto/rsa/padding.c
    ninja: build stopped: subcommand failed.
    build/core/ninja.mk:148: recipe for target 'ninja_wrapper' failed
    make: *** [ninja_wrapper] Error 1
    解决方法:刚开始编译就出现问题,首先想到的就是环境没有配对,又出现了
    "ninja_wrapper"

    这样的字样,估计是jack的问题,于是看了下home下是否有jack相关配置文件,结果不出所料,没有看到jack的配置文件,于是执行如下命令进行jack 初始化配置即解决问题

    ll@ll-pc:~/android/aosp/prebuilts/sdk/tools$ ls
    Android.mk                jack-server-4.8.ALPHA.jar
    darwin                    jack_server_setup.mk
    dx                        jack_versions.mk
    jack                      jills
    jack-admin                lib
    jack-annotations.jar      linux
    jack-coverage-plugin.jar  mainDexClasses
    jack-diagnose             mainDexClasses.rules
    jack_for_module.mk        README-jack-code-coverage.md
    jack-jacoco-reporter.jar  README-jack-server.md
    jack-launcher.jar         windows
    jacks
    ll@ll-pc:~/android/aosp/prebuilts/sdk/tools$ ./jack-admin install-server jack-launcher.jar jack-server-4.8.ALPHA.jar
    Installing jack server in "/home/ll/.jack-server"
    
    Warning:
    JKS 密钥库使用专用格式。建议使用 "keytool -importkeystore -srckeystore /home/ll/.jack-server/server.jks -destkeystore /home/ll/.jack-server/server.jks -deststoretype pkcs12" 迁移到行业标准格式 PKCS12。
    
    Warning:
    JKS 密钥库使用专用格式。建议使用 "keytool -importkeystore -srckeystore /home/ll/.jack-server/client.jks -destkeystore /home/ll/.jack-server/client.jks -deststoretype pkcs12" 迁移到行业标准格式 PKCS12。
    ll@ll-pc:~/android/aosp/prebuilts/sdk/tools$ 
    


  3. intermediates/build.prop ) && (cat out/target/product/mini-emulator-armv7-a-neon/android-info.txt | grep 'require version-' | sed -e 's/require version-/ro.build.expect./g' >> out/target/product/mini-emulator-armv7-a-neon/obj/ETC/system_build_prop_intermediates/build.prop ) && (build/tools/post_process_props.py out/target/product/mini-emulator-armv7-a-neon/obj/ETC/system_build_prop_intermediates/build.prop )"
    error: ro.build.fingerprint cannot exceed 91 bytes: Android/mini_emulator_arm64/mini-emulator-armv7-a-neon:7.1.1/N8I11B/ll07151211:userdebug/test-keys (98)
    [ 17% 5755/33411] host C: sqlite3 <= external/sqlite/dist/sqlite3.c
    ninja: build stopped: subcommand failed.
    build/core/ninja.mk:148: recipe for target 'ninja_wrapper' failed
    make: *** [ninja_wrapper] Error 

解决方法

这里是说value的长度超过限制

  • 修改 build/tools/post_process_props.py 如下:

PROP_NAME_MAX = 31

# PROP_VALUE_MAX = 91

PROP_VALUE_MAX = 127

  • 修改 bionic/libc/include/sys/system_properties.h 如下:
#define PROP_NAME_MAX   32
// #define PROP_VALUE_MAX  92
#define PROP_VALUE_MAX  128

    

  •  修改  native/cmds/installd/installd_deps.h

// Size constants. Should be checked to be equal to the cutils requirements.
constexpr size_t kPropertyKeyMax = 32u;
//constexpr size_t kPropertyValueMax = 92u;
constexpr size_t kPropertyValueMax = 128u;


经过漫长的等待,终于编译完成

[ 94% 13560/14334] host Java: ahat-tests (out/...VA_LIBRARIES/ahat-tests_intermediates/classes)
注: art/tools/ahat/test/SortTest.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[ 95% 13721/14334] host Java: android-icu4j-ho...RIES/android-icu4j-host_intermediates/classes)
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: external/icu/android_icu4j/src/main/java/android/icu/impl/Relation.java使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[ 96% 13859/14334] host Java: android-icu4j-te...ndroid-icu4j-tests-host_intermediates/classes)
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
注: 某些输入文件使用了未经检查或不安全的操作。
注: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[100% 14334/14334] host Executable: primitives...itives_tests_intermediates/primitives_tests32)

#### make completed successfully (01:10:01 (hh:mm:ss)) ####

因为我编译的是

 mini_emulator_x86_64-userdebug

模拟器版本,所以可以在pc端打开虚拟机


猜你喜欢

转载自blog.csdn.net/w1143408997/article/details/80993464