Android 4.0源码下载以及编译

写在前面:

    环境要求 系统 Ubuntu 14 (32 bit)
    由于 Android 5.0 的编译需要 64 bit 系统,因此只能编译 Android 4.0

   由于 Google 被墙,所以是从清华大学的服务器下载的 

         https://aosp.tuna.tsinghua.edu.cn/


    注:

        红色的文字是和正常的下载方式的对比,下载过程可以忽略这些红色的语句。

1.Ubuntu安装git

安装git

sudo apt-get install git-core

安装curl

sudo apt-get install git-core curl


2.下载并配置repo

A、mkdir ~/bin

   PATH=~/bin:$PATH

   git clone git://aosp.tuna.tsinghua.edu.cn/android/git-repo.git

   curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo 

B.步骤A中得到的git-repo中的repo文件拷贝到bin目录

   cp git-repo/repo ~/bin/

C.修改repo文件,修改REPO_URL

   sudo gedit ~/bin/repo

 在该文件中修改

   REPO_URL = 'git://aosp.tuna.tsinghua.edu.cn/android/git-repo'


我已经下载好的git-repo下载地址   http://download.csdn.net/detail/ly0904010214/8980621  

3.初始化repo

在ubuntu14.10上,建立放置源码的文件夹

 mkdir anroid

 cd android

 git config --global user.email "你的邮箱"

 git config --global user.name "你的用户名"

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

 repo init -u git://git.omapzoom.org/platform/manifest -b android-2.3.5_r1

关于上面 android-4.0.1_r1 下载的源码版本如果想下载其他版本,只需要将这个名字替换成相应版本的名字即可。



4.开始下载

  repo sync

  如果下载中断可以再次执行 repo sync



5.下载完成

  android 文件夹下的目录结构

     

6.编译前的准本工作

  1.安装JDK。由于编译Android 4.0需要在JDK 1.6的环境下进行,而系统中默认自带的JDK为1.8版本。

    因此需要卸载系统自带的JDK,然后安装JDK 1.6,具体方法如下:

    卸载系统自带的JDK sudo apt-get purge default-jdk

       安装JDK 1.6                 
       sh ./jdk-6u45-linux-x64.bin
       sudo vi /etc/environment
        PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/conan/tookit/jdk1.6.0_45/bin"
     JAVA_HOME=/home/conan/tookit/jdk1.6.0_45

    jdk-6u45-linux-i586.bin下载地址  http://download.csdn.net/detail/ly0904010214/8980729

  2.安装gcc 和 g++。由于编译Android 4.0需要在4.4版本下进行,而系统中为4.6版本。
    因此需要安装4.4版本,具体方法如下:

    查看gcc版本和g++版本
          /usr/bin$ ls -l gcc*
     /usr/bin$ ls -l g++*
      
    安装gcc和g++ 4.4版本
    sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib

    修改gcc链接
    sudo mv gcc gcc.bak
    sudo ln -s gcc-4.4 gcc

    修改g++链接
    sudo mv g++ g++.bak
    sudo ln -s g++-4.4 g++

    查看gcc和g++版本号
    gcc-v
    g++-v

  3. 安装依赖的包

    sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils


    4. 开始准备编译

   source build/envsetup.sh
   lunch full-eng

    make -j2(此处用2个线程编译)   或    make

   

    5.运行模拟器

        emulator



    注:常见问题
1. Error:

frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<android::String8, android::sp<AaptDir> >’ are not found by unqualified lookup


frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead


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


Fix:


vi frameworks/base/tools/aapt/Android.mk



Add '-fpermissive' to line 31:


LOCAL_CFLAGS += -Wno-format-y2k -fpermissive



2.Error:


frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]


frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<android::String8, android::wp<android::AssetManager::SharedZip> >’ are not found by unqualified lookup



frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead


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



Fix:


vi frameworks/base/libs/utils/Android.mk



Add '-fpermissive' to line 64:


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



3.Error:


external/srec/tools/thirdparty/OpenFst/fst/lib/cache.h:136:11: note: use ‘this->SetState’ instead


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



Fix:


cd external/srec


wget "https://github.com/CyanogenMod/android_external_srec/commit/4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff"


patch -p1 < 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff


rm -f 4d7ae7b79eda47e489669fbbe1f91ec501d42fb2.diff


cd ../..



4.Error:


development/tools/emulator/opengl/host/tools/emugen/main.cpp:79:9: error: ‘optind’ was not declared in this scope


development/tools/emulator/opengl/host/tools/emugen/main.cpp:92:45: error: ‘optind’ was not declared in this scope


make: *** [out/host/linux-x86/obj/EXECUTABLES/emugen_intermediates/main.o] Error 1



Fix:


vi development/tools/emulator/opengl/host/tools/emugen/main.cpp



Add '#include <getopt.h>' to list of includes:


#include <getopt.h>



5.Error:


host C++: liboprofile_pp <= external/oprofile/libpp/arrange_profiles.cpp


In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:


external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]


make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1



Fix:


vi external/oprofile/libpp/format_output.h



Remove 'mutable' from 'mutable counts_t & counts;' on line 94:


counts_t & counts;



6.Error:


development/tools/emulator/opengl/shared/OpenglCodecCommon/GLSharedGroup.cpp:345:65:   required from here



frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]


frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<unsigned int, ShaderData*>’ are not found by unqualified lookup



frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead


make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libOpenglCodecCommon_intermediates/GLSharedGroup.o] Error 1



Fix:


vi development/tools/emulator/opengl/Android.mk



Add '-fpermissive' to line 25:


EMUGL_COMMON_CFLAGS := -DWITH_GLES2 -fpermissive



7.Error:


/usr/bin/ld: note: 'XInitThreads' is defined in DSO /lib/libX11.so.6 so try adding it to the linker command line


/lib/libX11.so.6: could not read symbols: Invalid operation


collect2: error: ld returned 1 exit status


make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_renderer_intermediates/emulator_renderer] Error 1



Fix:


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



#ifeq ($(HOST_OS),windows)


#LOCAL_LDLIBS += -lws2_32 



8.Error:


external/llvm/include/llvm/ADT/PointerUnion.h:56:10: error: enumeral mismatch in conditional expression: ‘llvm::PointerLikeTypeTraits<llvm::PointerUnion<clang::Stmt*, const clang::Type*> >::<anonymous enum>’ vs ‘llvm::PointerLikeTypeTraits<clang::ObjCInterfaceDecl*>::<anonymous enum>’ [-Werror]


cc1plus: all warnings being treated as errors


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



Fix:


vi frameworks/compile/slang/Android.mk



Remove '-Werror' from line 22:


local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter 



9.Error:

frameworks/base/libs/rs/rsFont.cpp:224:76:   required from here



frameworks/base/include/utils/KeyedVector.h:193:31: error: ‘indexOfKey’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]


frameworks/base/include/utils/KeyedVector.h:193:31: note: declarations in dependent base ‘android::KeyedVector<unsigned int, android::renderscript::Font::CachedGlyphInfo*>’ are not found by unqualified lookup



frameworks/base/include/utils/KeyedVector.h:193:31: note: use ‘this->indexOfKey’ instead


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



Fix:


vi frameworks/base/libs/rs/Android.mk



Add '-fpermissive' to line 183


LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fpermissive



10.Error:


external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token


......


external/mesa3d/src/glsl/linker.cpp:1734:59: error: ‘offsetof’ was not declared in this scope


make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1



Fix:


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>



11.Error:


external/gtest/src/../include/gtest/gtest-param-test.h:287:58: note: ‘template<class Container> testing::internal::ParamGenerator<typename Container::value_type> testing::ValuesIn(const Container&)’ declared here, later in the translation unit


make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_host_intermediates/gtest-all.o] Error 1



Two fixes required:


1)


vi external/gtest/src/Android.mk



Add '-fpermissive' to lines 52 and 70 (both lines contain same info)


LOCAL_CFLAGS += -O0 -fpermissive



2)


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>



12.Error:


host Executable: test-librsloader (out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader)


out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Signals.o):在函数‘PrintStackTrace’中:


/home/crow/works/Android_src/external/llvm/lib/Support/Unix/Signals.inc:219:对‘dladdr’未定义的引用


/home/crow/works/Android_src/external/llvm/lib/Support/Unix/Signals.inc:231:对‘dladdr’未定义的引用


out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Threading.o):在函数‘llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)’中:


/home/crow/works/Android_src/external/llvm/lib/Support/Threading.cpp:96:对‘pthread_create’未定义的引用


/home/crow/works/Android_src/external/llvm/lib/Support/Threading.cpp:100:对‘pthread_join’未定义的引用


/home/crow/works/Android_src/external/llvm/lib/Support/Threading.cpp:91:对‘pthread_attr_setstacksize’未定义的引用


out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o):在函数‘llvm::sys::MutexImpl::MutexImpl(bool)’中:


/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:69:对‘pthread_mutexattr_init’未定义的引用


/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:75:对‘pthread_mutexattr_settype’未定义的引用


/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:80:对‘pthread_mutexattr_setpshared’未定义的引用


/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:89:对‘pthread_mutexattr_destroy’未定义的引用


out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o):在函数‘llvm::sys::MutexImpl::tryacquire()’中:


/home/crow/works/Android_src/external/llvm/lib/Support/Mutex.cpp:143:对‘pthread_mutex_trylock’未定义的引用


collect2: 错误: ld 返回 1


make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] 错误 1



Fix:



$vi external/llvm/llvm-host-build.mk +


LOCAL_LDLIBS := -lpthread -ldl




13.Error:


dalvik/vm/native/dalvik_system_Zygote.cpp:193:19: error: aggregate ‘setrlimitsFromArray(ArrayObject*)::rlimit rlim’ has incomplete type and cannot be defined




dalvik/vm/native/dalvik_system_Zygote.cpp: In function ‘int setrlimitsFromArray(ArrayObject*)’:dalvik/vm/native/dalvik_system_Zygote.cpp:199:19: error: aggregate ‘setrlimitsFromArray(ArrayObject*)::rlimit rlim’ has incomplete type and cannot be defined    struct rlimit rlim;




dalvik/vm/native/dalvik_system_Zygote.cpp:222:43: error: ‘setrlimit’ was not declared in this scope        err = setrlimit(contents[0], &rlim);




make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libdvm_intermediates/native/dalvik_system_Zygote.o] Error 1make: *** Waiting for unfinished jobs....



Fix:


在dalvik/vm/native/dalvik_system_Zygote.cpp中间增加一个头文件定义#include <sys/resource.h>



#include "Dalvik.h"


#include "native/InternalNativePriv.h"


#include <sys/resource.h>





14.Error:

external/yaffs2/yaffs2/yaffs_tagsvalidity.h:23:6: warning: redundant redeclaration of ‘yaffs_InitialiseTags’ [-Wredundant-decls]

external/yaffs2/yaffs2/yaffs_guts.h:888:6: note: previous declaration of ‘yaffs_InitialiseTags’ was here
host C: mkyaffs2image <= external/yaffs2/yaffs2/yaffs_tagsvalidity.c
host C++: obbtool <= frameworks/base/tools/obbtool/Main.cpp
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
:0:0: note: this is the location of the previous definition
In file included from external/yaffs2/yaffs2/yaffs_tagsvalidity.c:17:0:
external/yaffs2/yaffs2/yaffs_tagsvalidity.h:23:6: warning: redundant redeclaration of ‘yaffs_InitialiseTags’ [-Wredundant-decls]
external/yaffs2/yaffs2/yaffs_guts.h:888:6: note: previous declaration of ‘yaffs_InitialiseTags’ was here
host C: parseStringTest <= external/srec/tools/parseStringTest/parseStringTest.c
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1
make: *** Waiting for unfinished jobs....
host C++: post_trace <= sdk/emulator/qtools/post_trace.cpp
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition


Fix:

参照    2.安装gcc 和 g++。由于编译Android 4.0需要在4.4版本下进行,而系统中为4.6版本。
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值