Ubuntu1404 AMD64编译Android4.0.1源码

ubuntu 1404 AMD64 下载编译Android4.0

安装
  1. 搭建编译环境:需要的软件包
  2. 下载repo参考
1
2
3
4
5
6
7
8
mkdir ~/bin
PATH=~/bin:$PATH
cd ~/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod +x repo
# 配置repo更新,使用tuna镜像源更新,将下面内容复制到~/.bashrc里
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'
source ~/.bashrc
  1. 安装JDK1.6参考
  • 下载:https://www.oracle.com/java/technologies/javase-java-archive-javase6-downloads.html ,我下的是:jdk-6u45-linux-x64.bin,将它复制到/usr/java,改为可执行,执行安装,添加到PATH环境,具体操作如下:

    mkdir /usr/java

    cp ~/Downloads/jdk-6u45-linux-x64.bin /usr/java

    cd /usr/java

    chmod +x jdk-6u45-linux-x64.bin

    ./jdk-6u45-linux-x64.bin

    sudo rm -rf jdk-6u45-linux-x64.bin

    #配置环境

    sudo vim ~/.bashrc

    export ANDROID_JAVA_HOME=’/usr/java/jdk1.6.0_45’
    export PATH=”$ANDROID_JAVA_HOME/bin:$PATH”
    export CLASSPATH=”$ANDROID_JAVA_HOME/lib/dt.jar:$ANDROID_JAVA_HOME/lib/tools.jar”

    source ~/.bashrc

  1. 同步源码

    mkdir AndroidResource

    cd AndroidResource

    repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.0.1_r1

    repo sync

  2. 编译源码(过程会有一些错,在文章的最底部)

    source build/envsetup.sh

    ./build/envsetup.sh

    m

  3. 编译SDK(过程会有一些错,在文章的最底部)

    m sdk

  4. 运行

    • 设置环境变量

      export PATH=”/AndroidResource/out/host/linux-x86/bin:$PATH”
      export ANDROID_PRODUCT_OUT=
      /AndroidResource/out/target/product/generic

    其中*/AndroidResource/out/host/linux-x86/bin中有emulator指令,/AndroidResource/out/target/product/generic*有Android镜像

    • 将编译的Android镜像运行到emulator上

      emulator-arm //或 emulator

编译Android源码遇到的错误
  1. error: sys/cdefs.h: No such file or directory

sudo apt-get install libc6-dev-i386

  1. 在安装JDK6之后,还是找不到jdk6

    • 打开/build/core/find-jdk-tools-jar.sh可以发现,缺少$ANDROID_JAVA_HOME,把~/.bashrc 中的JAVA_HOME改成ANDROID_JAVA_HOME

    • 修改权限存放Android源码的目录:sudo chmod 755 -R ~/AndroidResource/

  2. not found bits/c++config.h,参考

    • sudo apt-get install gcc-4.8-multilib g++-4.8-multilib

  3. [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/AaptAssets.o] Error 1

    • 在*/frameworks/base/tools/aapt/Android.mk* 第31行处改为

      LOCAL_CFLAGS += -Wno-format-y2k -fpermissive

  4. [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/AssetManager.o] Error 1

  • 在/frameworks/base/libs/utils/Android.mk 第64行 改为

    LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

  1. [out/host/linux-x86/obj/EXECUTABLES/grxmlcompile_intermediates/grxmlcompile.o] Error 1

  2. [out/host/linux-x86/obj/SHARED_LIBRARIES/libdvm_intermediates/native/dalvik_system_Zygote.o] Error 1

    • 添加 #include <sys/resource.h>dalvik/vm/native/dalvik_system_Zygote.cpp
  3. [out/host/linux-x86/obj/EXECUTABLES/emugen_intermediates/main.o] Error 1

    • development/tools/emulator/opengl/host/tools/emugen/main.cpp 中添加 #include <getopt.h>
  4. [out/host/linux-x86/obj/STATIC_LIBRARIES/libOpenglCodecCommon_intermediates/GLSharedGroup.o] Error 1

    • development/tools/emulator/opengl/Android.mk 第25行 改为

      EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive

  5. [out/host/linux-x86/obj/lib/libOpenglRender.so] Error 1

    • sudo apt-get install libx11-dev:i386

  6. [out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/emulator_renderer] Error 1

    • development/tools/emulator/opengl/host/renderer/Android.mk 新增一行 LOCAL_LDLIBS += -lX11,如下:
    1
    2
    3
    LOCAL_SRC_FILES := main.cpp
    LOCAL_CFLAGS += -O0 -g
    LOCAL_LDLIBS += -lX11
  7. /usr/include/zlib.h:34:19: fatal error: zconf.h: No such file or directory -> #include “zconf.h”

    • 在usr/include中没有找到zconf.h,由于zlib1g-dev的路径改变,才找不到。解决办法:将新路径的zconf.h拷贝到usr/include目录下,如下:

    sudo cp /usr/include/x86_64-linux-gnu/zconf.h /usr/include/

  8. [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1

    • 将*/build/core/combo/HOST_linux-x86.mk* 中的 HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0 修改为

      HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

  9. [out/host/linux-x86/obj/lib/libGLES_CM_translator.so] Error 1

    • 如果在/usr/lib/i386-linux-gnu/中没有发现mesa文件夹,安装(参考

      sudo apt-get install libc6:i386
      sudo apt-get install libgl1-mesa-glx-lts-trusty:i386

      有的话,执行(libGL.so.1查看自己的版本)

      sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so

  10. [out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs.o] Error 1

  • frameworks/compile/slang/Android.mk第21行local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter注释掉
  1. [out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMJIT_intermediates/Intercept.o] Error 1

    • external/llvm/lib/ExecutionEngine/JIT/Intercept.cpp中添加

    • #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>

  2. [out/target/product/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates/Source/WebCore/html/DocTypeStrings.cpp] Error 2

    • sudo apt-get install libswitch-perl

  3. [out/host/linux-x86/obj/STATIC_LIBRARIES/libRS_intermediates/rsFont.o] Error 1

  • frameworks/base/libs/rs/Android.mk 中第183行后面添加-fpermissive例如:LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive*
  1. [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1
  • external/oprofile/libpp/format_output.h中第94行,将mutable移除 ,改为counts_t & counts;
  1. [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1
- 在*external/llvm/llvm-host-build.mk*中添加

  > LOCAL_LDLIBS := -lpthread -ldl
  1. [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1

    • 1)在external/gtest/src/Android.mk的52行和70行添加*-fpermissive*

      LOCAL_CFLAGS += -O0 -fpermissive

    • 2)在external/gtest/include/gtest/internal/gtest-param-util.h中添加几个头文件

      #include
      #include
      #include <gtest/internal/gtest-port.h>

编译SDK遇到的错误
  1. development/build/sdk.atree:229: couldn't locate source file: framework/layoutlib-tests.jar
    development/build/sdk.atree:230: couldn't locate source file: system/app/ConnectivityTest.apk
    development/build/sdk.atree:231: couldn't locate source file: system/app/GpsLocationTest.apk
    sdk/build/tools.atree:47: couldn't locate source file: usr/share/pc-bios/bios.bin
    sdk/build/tools.atree:48: couldn't locate source file: usr/share/pc-bios/vgabios-cirrus.bin
    sdk/build/tools.atree:146: couldn't locate source file: framework/ddmlib-tests.jar
    sdk/build/tools.atree:147: couldn't locate source file: framework/ninepatch-tests.jar
    sdk/build/tools.atree:148: couldn't locate source file: framework/common-tests.jar
    sdk/build/tools.atree:150: couldn't locate source file: framework/sdkuilib-tests.jar
    make: *** [out/host/linux-x86/sdk/android-sdk_eng.d_linux-x86.zip] Error 44
    
    • 1)类似XXX-tests.jar的问题,通过在*AndroidSRC/out/host/linux-x86/framework/*,中ddmlib.jar复制一份名为ddmlib-tests.jar。

      2)运行lunch sdk-eng 再执行m sdk

-------------本文结束感谢您的阅读-------------