ubuntu 14.04系统 Android 4.0.1 源码编译过程

Android 4.0.1 源码编译过程

一、环境准备

  1. 系统:ubuntu 14.04 64bit

  2. Java: 1.6.0_45

  3. 安装需要的库:

sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
  lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
  libgl1-mesa-dev libxml2-utils xsltproc unzip

二、下载源代码

  • 安装 Repo
    1. 创建 bin 目录
      $ mkdir ~/bin
      $ PATH=~/bin:$PATH

    2. 下载 rope tool
      $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
      $ chmod a+x ~/bin/repo

  • 初始化一个 Repo client
    1. 创建目录
      $ mkdir WORKING_DIRECTORY
      $ cd WORKING_DIRECTORY
    2. 配置git
      $ git config --global user.name "Your Name"
      $ git config --global user.email "you@example.com"
    3. 初始化 repo
      repo init -u https://android.googlesource.com/platform/manifest
      -b android-4.0.1_r1
  • 下载 Android 源码

    $ repo sync

三、编译源码

  • 初始化环境

    $ source build/envsetup.sh

  • 选择target

    $ lunch
    选择默认的full-eng就好,这个表示运行在模拟器的编译方式

  • 编译源码

    $ make -j4 (可以根据内核个数选用不同的编译命令)

  • 错误处理(在编译源码时会出现不少错误)
    1. 错误详情:
      out/host/linux-x86/obj/lib/libOpenglRender.so
      解决办法:
      安装32位的libX11库, sudo apt-get install libx11-dev:i386

    2. 错误详情:
      out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/emulator_renderer
      解决办法:
      vi development/tools/emulator/opengl/host/renderer/Android.mk
      Add new entry 'LOCAL_LDLIBS += -lX11' after line 6 as shown:
      LOCAL_SRC_FILES := main.cpp
      LOCAL_CFLAGS += -O0 -g
      LOCAL_LDLIBS += -lX11

    3. 错误详情:
      out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o
      解决办法:
      vim /build/core/combo/HOST_linux-x86.mk
      将以下语句
      HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
      修改为
      HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

    4. 错误详情:
      out/host/linux-x86/obj/lib/libGLES_CM_translator.so
      解决办法:
      sudo apt-get installibgl1-mesa-glx:i386
      sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

    5. 错误详情:
      out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/AaptAssets.o
      解决办法:
      vi frameworks/base/tools/aapt/Android.mk
      Add '-fpermissive' to line 31:
      LOCAL_CFLAGS += -Wno-format-y2k -fpermissive

    6. 错误详情:
      out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/AssetManager.o
      解决办法:
      vi frameworks/base/libs/utils/Android.mk
      Add '-fpermissive' to line 64:
      LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

    7. 错误详情:
      out/host/linux-x86/obj/EXECUTABLES/grxmlcompile_intermediates/grxmlcompile.o
      解决办法:
      cd external/srec
      wget "https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff"
      patch -p1 < 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
      rm -f 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff
      cd ../..

    8. 错误详情:
      out/host/linux-x86/obj/EXECUTABLES/emugen_intermediates/main.o
      解决办法:
      vi development/tools/emulator/opengl/host/tools/emugen/main.cpp
      Add '#include <getopt.h>' to list of includes:
      #include <getopt.h>

    9. 错误详情:
      out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o
      解决办法:
      vi external/oprofile/libpp/format_output.h
      Remove 'mutable' from 'mutable counts_t & counts;' on line 94:
      counts_t & counts;

    10. 错误详情:
      out/host/linux-x86/obj/STATIC_LIBRARIES/libOpenglCodecCommon_intermediates/GLSharedGroup.o
      解决办法:
      vi development/tools/emulator/opengl/Android.mk
      Add '-fpermissive' to line 25:
      EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive

    11. 错误详情:
      out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs.o
      解决办法:
      vi frameworks/compile/slang/Android.mk
      Remove '-Werror' from line 22:
      local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter

    12. 错误详情:
      out/host/linux-x86/obj/STATIC_LIBRARIES/libRS_intermediates/rsFont.o
      解决办法:
      vi frameworks/base/libs/rs/Android.mk
      Add '-fpermissive' to line 183
      LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive

    13. 错误详情:
      out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o
      解决办法:
      vi external/mesa3d/src/glsl/linker.cpp
      Add '#include <stddef.h>' to list of includes as shown:
      #include <climits>
      #include <stddef.h>
      #include <pixelflinger2/pixelflinger2_interface.h>

    14. 错误详情:
      out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o
      解决办法:
      vi external/gtest/src/Android.mk
      Add '-fpermissive' to lines 52 and 70 (both lines contain same info)
      LOCAL_CFLAGS += -O0 -fpermissive
      vi external/gtest/include/gtest/internal/gtest-param-util.h
      Add '#include <stddef.h>' to list of includes as shown:
      #include <vector>
      #include <cstddef>
      #include <gtest/internal/gtest-port.h>

    15. 错误详情:
      out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader
      解决办法:
      vi external/llvm/llvm-host-build.mk +
      LOCAL_LDLIBS := -lpthread -ldl

    16. 错误详情:
      out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMJIT_intermediates/Intercept.o
      解决办法:
      vim external/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
      add head files:
      #define _LARGEFILE64_SOURCE
      #include <stdlib.h>
      #include <stdio.h>
      #include <string.h>
      #include <unistd.h>
      #include <sys/types.h>
      #include <sys/stat.h>
      #include <fcntl.h>
      #include <errno.h>

  • 运行

    可以直接执行命令:$ emulator来运行
    如果找不到emulator命令需要按照下面的顺序再配置下环境:
    $ source build/envsetup.sh
    $ lunch full-eng
    $ emulator

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值