Ubuntu 16.04 编译Android 6.0系统源码

前端之家收集整理的这篇文章主要介绍了Ubuntu 16.04 编译Android 6.0系统源码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

准备环境

1.安装open-jdk7
【使用open-jdk8会报错】,原因是:
在build/core/main.mk中默认指定的是jdk1.7

# Check for the correct version of java,should be 1.7 by
# default,and 1.8 if EXPERIMENTAL_USE_JAVA8 is set
ifneq ($(EXPERIMENTAL_USE_JAVA8),)
required_version := "1.8.x"
required_javac_version := "1.8"
java_version := $(shell echo '$(java_version_str)' | grep 'openjdk .*[ "]1\.8[\. "$$]')
javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.8[\. "$$]')
else # default
required_version := "1.7.x"
required_javac_version := "1.7"
java_version := $(shell echo '$(java_version_str)' | grep '^java .*[ "]1\.7[\. "$$]')
javac_version := $(shell echo '$(javac_version_str)' | grep '[ "]1\.7[\. "$$]')
endif # if EXPERIMENTAL_USE_JAVA8

我开始就是安装了open-jdk8,然后编译不过,看到这里默认是1.7,如果是试验环境,所以又重新安装的1.7。
这个安装完以后,就准备开始编译Android源码。

2.编译前配置
在.bashrc文件添加:export USE_CCACHE = 1,操作如下:

echo export USE_CCACE=1 >> ~/.bashrc

为了提高编译效率,设置编译器高速缓存。执行以下命令:

prebuilts/misc/linux-x86/ccache/ccache -M 30G

-M 30G 两个参数表示设置30G大小的空间作为缓存,这个数值可以根据自己的硬盘空间大小继续调整.

编译

接着导入编译Android源码所需的环境变量和其它参数,运行以下命令

source build/envsetup.sh

结果如下:

dongqiang@dongqiang-Lenovo-Y50p-70:/media/dongqiang/learn/learn/Android/android-6.0.0_r1$ source build/envsetup.sh
including device/asus/deb/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including device/asus/fugu/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-mips/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/htc/flounder/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/moto/shamu/vendorsetup.sh
including sdk/bash_completion/adb.bash
dongqiang@dongqiang-Lenovo-Y50p-70:/media/dongqiang/learn/learn/Android/android-6.0.0_r1$ 

接着输入lunch

dongqiang@dongqiang-Lenovo-Y50p-70:/media/dongqiang/learn/learn/Android/android-6.0.0_r1$ 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_deb-userdebug 8. aosp_flo-userdebug 9. full_fugu-userdebug 10. aosp_fugu-userdebug 11. mini_emulator_arm64-userdebug 12. m_e_arm-userdebug 13. mini_emulator_mips-userdebug 14. mini_emulator_x86_64-userdebug 15. mini_emulator_x86-userdebug 16. aosp_flounder-userdebug 17. aosp_hammerhead-userdebug 18. aosp_hammerhead_fp-userdebug 19. aosp_shamu-userdebug Which would you like? [aosp_arm-eng] 

这里选择1,会出现以下提示信息,告诉我们编译的源码的一些相关信息:

 Which would you like? [aosp_arm-eng] 1 ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=6.0 TARGET_PRODUCT=aosp_arm TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm TARGET_ARCH_VARIANT=armv7-a TARGET_cpu_VARIANT=generic TARGET_2ND_ARCH= TARGET_2ND_ARCH_VARIANT= TARGET_2ND_cpu_VARIANT= HOST_ARCH=x86_64 HOST_OS=linux HOST_OS_EXTRA=Linux-4.4.0-34-generic-x86_64-with-Ubuntu-16.04-xenial HOST_BUILD_TYPE=release BUILD_ID=MRA58K OUT_DIR=out ============================================ dongqiang@dongqiang-Lenovo-Y50p-70:/media/dongqiang/learn/learn/Android/android-6.0.0_r1$ 

开始编译

make -j8

Error:

1.frameworks/base/tools/aidl/aidl_language_y.y

Import includes file: out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/import_includes
    Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y
    prebuilts/misc/linux-x86/bison/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: prebuilts/misc/linux-x86/bison/bison: No such file or directory
    build/core/binary.mk:609: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp' Failed
    make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error 127
    make: *** Waiting for unfinished jobs....
    Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
    frameworks/base/tools/aidl/aidl_language_l.l:55: warning,rule cannot be matched
    flex-2.5.39: fatal internal error,exec of /usr/bin/m4 Failed
    build/core/binary.mk:646: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp' Failed
    make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp] Broken pipe
    make: *** Deleting file 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_l.cpp'
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    #### make Failed to build some targets (08:18 (mm:ss)) ####

解决方法

sudo apt-get install bison

接着编译还是错

Yacc: aidl <= frameworks/base/tools/aidl/aidl_language_y.y
Lex: aidl <= frameworks/base/tools/aidl/aidl_language_l.l
prebuilts/misc/linux-x86/bison/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: prebuilts/misc/linux-x86/bison/bison: No such file or directory
build/core/binary.mk:609: recipe for target 'out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp' Failed
make: *** [out/host/linux-x86/obj/EXECUTABLES/aidl_intermediates/aidl_language_y.cpp] Error 127
make: *** Waiting for unfinished jobs....

2.

/bin/bash: xmllint: command not found
/bin/bash: xmllint: command not found
build/core/Makefile:34: recipe for target 'out/target/product/generic/system/etc/apns-conf.xml' Failed
make: *** [out/target/product/generic/system/etc/apns-conf.xml] Error 127
make: *** Waiting for unfinished jobs....
build/core/Makefile:34: recipe for target 'out/target/product/generic/system/etc/permissions/handheld_core_hardware.xml' Failed
make: *** [out/target/product/generic/system/etc/permissions/handheld_core_hardware.xml] Error 127

解决办法:

sudo apt-get install  libxml2-utils

3.
接下来还是错:

Device TableGen (gen-intrinsic): libLLVMipa <= external/llvm/include/llvm/IR/Intrinsics.td
clang: error: linker command Failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:51: recipe for target 'out/host/linux-x86/obj/lib/libart.so' Failed
make: *** [out/host/linux-x86/obj/lib/libart.so] Error 1
make: *** Waiting for unfinished jobs....
clang: error: linker command Failed with exit code 1 (use -v to see invocation)
build/core/host_shared_library_internal.mk:51: recipe for target 'out/host/linux-x86/obj/lib/libartd.so' Failed
make: *** [out/host/linux-x86/obj/lib/libartd.so] Error 1

【我安装了下下面这些,究竟有没有用还需要试验:】

sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib

然后在网上搜了下,这个问题的解决方法

http://forum.xda-developers.com/chef-central/android/guide-how-to-setup-ubuntu-16-04-lts-t3363669/page2

注意看这个帖子的15楼,哈哈,这个时候找到解决方法了,再修改art/build/Android.common_build.mk文件

ifneq ($(WITHOUT_HOST_CLANG),true)

改为:

ifeq ($(WITHOUT_HOST_CLANG),false)

执行:

sudo vi art/build/Android.common_build.mk
    /WITHOUT_HOST_CLANG  #搜索该字符的位置

在第74行:

# Clang build support.
    # Host.
    ART_HOST_CLANG := false
    ifneq ($(WITHOUT_HOST_CLANG),false)
      # By default,host builds use clang for better warnings.
      ART_HOST_CLANG := true
    endif

进行修改,然后继续make -j8编译。反复执行几次就可以了。

编译成功

Creating filesystem with parameters:
        Size: 1610612736
        Block size: 4096
        Blocks per group: 32768
        Inodes per group: 8192
        Inode size: 256
        Journal blocks: 6144
        Label: system
        Blocks: 393216
        Block groups: 12
        Reserved block group size: 95
    Created filesystem with 1696/98304 inodes and 138385/393216 blocks
    Install system fs image: out/target/product/generic/system.img
    out/target/product/generic/system.img+ maxsize=1644333504 blocksize=2112 total=1610612736 reserve=16610880

    #### make completed successfully (03:39:54 (hh:mm:ss)) ####

    dongqiang@dongqiang-Lenovo-Y50p-70:/media/dongqiang/learn/learn/Android/android-6.0.0_r1$ 

进入out目录可以看到编译生成文件

dongqiang@dongqiang-Lenovo-Y50p-70:/media/dongqiang/learn/learn/Android/android-6.0.0_r1/out/target/product/generic$ ll
    total 1590669
    drwxrwxrwx 1 dongqiang dongqiang       4096 924 15:02 ./
    drwxrwxrwx 1 dongqiang dongqiang          0 922 23:11 ../
    -rwxrwxrwx 1 dongqiang dongqiang          7 924 10:14 android-info.txt*
    drwxrwxrwx 1 dongqiang dongqiang          0 924 13:14 cache/
    -rwxrwxrwx 1 dongqiang dongqiang   69206016 924 13:14 cache.img*
    -rwxrwxrwx 1 dongqiang dongqiang      70391 924 11:28 clean_steps.mk*
    drwxrwxrwx 1 dongqiang dongqiang          0 924 13:46 data/
    drwxrwxrwx 1 dongqiang dongqiang          0 924 13:09 dex_bootjars/
    drwxrwxrwx 1 dongqiang dongqiang          0 924 00:31 gen/
    -rwxrwxrwx 1 dongqiang dongqiang      70522 924 15:01 installed-files.txt*
    drwxrwxrwx 1 dongqiang dongqiang       4096 924 15:01 obj/
    -rwxrwxrwx 1 dongqiang dongqiang        761 924 11:28 prevIoUs_build_config.mk*
    -rwxrwxrwx 1 dongqiang dongqiang     888961 924 13:32 ramdisk.img*
    drwxrwxrwx 1 dongqiang dongqiang          0 924 13:32 recovery/
    drwxrwxrwx 1 dongqiang dongqiang       4096 924 13:32 root/
    drwxrwxrwx 1 dongqiang dongqiang       4096 924 13:31 symbols/
    drwxrwxrwx 1 dongqiang dongqiang       4096 924 14:13 system/
    -rwxrwxrwx 1 dongqiang dongqiang 1610612736 924 15:02 system.img*
    -rwxrwxrwx 1 dongqiang dongqiang  576716800 924 13:47 userdata.img*
    dongqiang@dongqiang-Lenovo-Y50p-70:/media/dongqiang/learn/learn/Android/android-6.0.0_r1/out/target/product/generic$

执行emulator


可以看到打开了模拟器.

原文链接:https://www.f2er.com/ubuntu/355920.html

猜你在找的Ubuntu相关文章