搭建Ubuntu14.04编译环境并下载源码

  • 要想在Ubuntu下编译Android源码,首先要搭建环境

    参考链接(官方):
    环境:http://source.android.com/source/initializing.html
    下载:http://source.android.com/source/downloading.html
    编译:http://source.android.com/source/building-running.html

    一、安装JDK

    到官网去下载后再安装

    官网:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

    \

    如果Ubuntu安装的是32位版本的,选择Linux x86版本,如果Ubuntu是64位的,那么应该选择Linux x64

    如果要下载历史版本可以参考:http://jingyan.baidu.com/article/9989c746064d46f648ecfe9a.html

    JDK6的下载地址:http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html

    下载完成后接下来就是要安装JDK,在Ubuntu下很多操作都需要Root权限,在切换权限时碰到一个问题su root切换失败,

    $ su - root
    Password:
    su: Authentication failure

    如果碰到以上问题可以尝试

    $ sudo passwd root
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully

    此时再输入su root就能切换到Root权限

    在home目录下创建一个android目录,把这个目录作为开发目录,开发用到的相关文件都存放在这里

    把下载的JDK拷到这个目录下

    \

    安装JDK 执行:$ sudo tar -zxvf jdk-8u5-linux-i586.gz

    \

    执行完后在当前目录下多了一个目录

    \

    \

    添加环境变量修改“bashrc”文件

    \

    在文件的最后添加 expor PATH=/home/android/jdk1.6.0_45/bin:$PATH

    \

    按“ESC” 输入:wq 存盘退出

    测试环境变量是否设置成功,如果能正确输出版本号说明设置成功

    \

    安装Android编译工具

    01. <a href="http://www.it165.net/pro/ydad/"target="_blank"class="keylink">Android</a>环境搭建步骤Ubuntu14.04
    02. 需要有良好的网络支持才能使用,如果没网络下面的安装无法进行
    03. 按以下顺序安装组件
    04.  
    05. 1、配置163的mirror
    06. 替换 /etc/apt/source.list中的源信息
    07. sudo gedit /etc/apt/sources.list  //修改更新源设置
    08.  
    09. // 将以下地址加入到sources.list里面
    10.  
    11. deb http://mirrors.163.com/ubuntu/ precise main restricted
    12. deb-src http://mirrors.163.com/ubuntu/ precise main restricted
    13. deb http://mirrors.163.com/ubuntu/ precise-updates main restricted
    14. deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted
    15. deb http://mirrors.163.com/ubuntu/ precise universe
    16. deb-src http://mirrors.163.com/ubuntu/ precise universe
    17. deb http://mirrors.163.com/ubuntu/ precise-updates universe
    18. deb-src http://mirrors.163.com/ubuntu/ precise-updates universe
    19. deb http://mirrors.163.com/ubuntu/ precise multiverse
    20. deb-src http://mirrors.163.com/ubuntu/ precise multiverse
    21. deb http://mirrors.163.com/ubuntu/ precise-updates multiverse
    22. deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse
    23. deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
    24. deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
    25. deb http://mirrors.163.com/ubuntu/ precise-security main restricted
    26. deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted
    27. deb http://mirrors.163.com/ubuntu/ precise-security universe
    28. deb-src http://mirrors.163.com/ubuntu/ precise-security universe
    29. deb http://mirrors.163.com/ubuntu/ precise-security multiverse
    30. deb-src http://mirrors.163.com/ubuntu/ precise-security multiverse
    31. deb http://extras.ubuntu.com/ubuntu precise main
    32. deb-src http://extras.ubuntu.com/ubuntu precise main
    33.  
    34. 2、apt-get update
    35.  
    36. 3、
    37. sudo apt-get install git gnupg flex bison gperf build-essential \
    38. zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
    39. libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
    40. libgl1-mesa-dev g++-multilib mingw32 tofrodos \
    41. python-markdown libxml2-utils xsltproc zlib1g-dev:i386
    42.  
    43. 提示:thismaby failed, install by error(apt-get install linux-libc-dev)
    44.  
    45. sudo apt-get install xutils-dev
    46. sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1/usr/lib/i386-linux-gnu/libGL.so
    47.  
    48. sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.8-dev
    49. sudo apt-get install build-essential zip curl libncurses5-dev zlib1g-dev tofrodos libglib2.0-dev
    50. sudo apt-get install libgmp3c2 libgmpxx4ldbl libgmp3-dev libmpc2 libmpc-dev libmpfr-dev libmpfr1ldbl libmpfr4

    下载Android源码

    Android的源码通过Git来管理,Android的网站上为我们准备好了一个repo脚本,repo是Google用Python脚本写的调用git的一个脚本,主要是用来下载、管理Android项目的软件仓库

    在Android的官网上有介绍如何下载源码:http://source.android.com/source/downloading.html

    \

    创建存放Android源码的目录

    \

    根据官网的提示 创建repo脚本保存目录,创建到/root目录下,将~/bin目录添加到PATH环境变量中

    \

    根据官网上的提示安装repo

    \

    1. $ mkdir ~/bin
    2. $ PATH=~/bin:$PATH
    3. $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    4. $ chmod a+x ~/bin/repo

    但无法连接成功,最近连google都上不了,估计很难下载到repo,可以使用VPN,http://a.wy002.com/495891

    没办法只能在网上找了别人下载的repo http://download.csdn.net/download/yangfeihu/4186145

    \

    下载的repo还是无法下载源码

    最后去申请了一个VPN帐号,有1G免费的可以用,就试着使用命令curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo 居然可以了。

    但是还是无法下载源码,报出如下信息

    01. root@ubuntu:/home/android/android_source# repo init -u https://android.googlesource.com/platform/manifest
    02. Traceback (most recent call last):
    03. File"/home/android/android_source/.repo/repo/main.py", line238, in <module>
    04. _Main(sys.argv[1:])
    05. File"/home/android/android_source/.repo/repo/main.py", line220, in _Main
    06. repo._Run(argv)
    07. File"/home/android/android_source/.repo/repo/main.py", line125, in _Run
    08. cmd.Execute(copts, cargs)
    09. File"/home/android/android_source/.repo/repo/subcmds/init.py", line259, in Execute
    10. self._SyncManifest(opt)
    11. File"/home/android/android_source/.repo/repo/subcmds/init.py", line152, in _SyncManifest
    12. m.Sync_LocalHalf(syncbuf)
    13. File"/home/android/android_source/.repo/repo/project.py", line1045, in Sync_LocalHalf
    14. ifcommitter_email == self.UserEmail:
    15. File"/home/android/android_source/.repo/repo/project.py", line580, in UserEmail
    16. self._LoadUserIdentity()
    17. File"/home/android/android_source/.repo/repo/project.py", line584, in _LoadUserIdentity
    18. u = self.bare_git.var('GIT_COMMITTER_IDENT')
    19. File"/home/android/android_source/.repo/repo/project.py", line1772, in runner
    20. p.stderr))
    21. error.GitError: manifests var:
    22. *** Please tell me who you are.
    23.  
    24. Run
    25.  
    26. git config --global user.email"you@example.com"
    27. git config --global user.name"Your Name"
    28.  
    29. to set your account'sdefaultidentity.
    30. Omit --global to set the identity only inthisrepository.
    31.  
    32. fatal: unable to auto-detect email address (got'root@ubuntu.(none)')

    根据提示

    Run
    git config --global user.email "you@example.com"
    git config --global user.name "Your Name"

    输入如下信息根据个人情况而定:

    root@ubuntu:/home/android/android_source# git config --global user.email "dengzhangtai@gmail.com"
    root@ubuntu:/home/android/android_source# git config --global user.name "dzt"

    初始化成功了

    01. root@ubuntu:/home/android/android_source# repo init -u https://android.googlesource.com/platform/manifest
    02. .repo/manifests/: discarding159commits removed from upstream
    03.  
    04. Your Name  [dzt]:
    05. Your Email [dengzhangtai@gmail.com]:
    06.  
    07. Your identity is: ls <dengzhangtai@gmail.com>
    08. isthiscorrect [y/n]? y
    09.  
    10. Testing colorized output (for'repo diff','repo status'):
    11. black    red      green    yellow   blue     magenta   cyan     white
    12. bold     dim      ul       reverse
    13. Enable color display inthisuser account (y/n)? y
    14.  
    15. repo initialized in /home/android/android_source
    正式下载源码,还是报错了
    01. root@ubuntu:/home/android/android_source# repo sync
    02. Fetching projects:  1% (2/172) 
    03. Initializing project platform/bionic ...
    04. fatal:'../platform/bionic.git'does not appear to be a git repository
    05. fatal: Could not read from remote repository.
    06.  
    07. Please make sure you have the correct access rights
    08. and the repository exists.
    09. error: Cannot fetch platform/bionic

    不清楚什么原因,把虚拟机重启了,再运行repo sync,就报如下错误

    1. The program'repo'is currently not installed. You can install it by typing:
    2. apt-get install phablet-tools
    叫我安装phablet-tools,那就安装吧,输入

    apt-get install phablet-tools

    安装完还是不行,真没办法了,下个源码折腾个半天

    再按这个步骤试下

    1. $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    2. $ chmod a+x ~/bin/repo
    3. $ mkdir WORKING_DIRECTORY
    4. $ cd WORKING_DIRECTORY
    5. $ repo init -u https://android.googlesource.com/platform/manifest
    6. $ repo sync
    \
    居然又可以了,我一直都是连着VPN的。

    又报出如下问题

    01. or: RPC failed; result=56, HTTP code =200
    02. error: RPC failed; result=56, HTTP code =200
    03. fatal: The remote end hung up unexpectedly
    04. fatal: early EOF
    05. fatal: index-pack failed
    06. fatal: The remote end hung up unexpectedly
    07. fatal: early EOF
    08. fatal: index-pack failed
    09. 1548.4M  157529k   0    0  9265     0 1:31:22 0:13:52 1:17:30    0
    10. curl: (56) Recv failure: Connection timed out
    11. 988.8M   98424k   0    0 10366     0 2:29:46 0:13:52 2:15:54    0
    12. curl: (56) Recv failure: Connection timed out
    13. remote: Sending approximately72.47MiB ...
    14. remote: Counting objects:25, done
    15. remote: Finding sources:100% (25/25)
    16. remote: Sending approximately47.99MiB ...
    17. remote: Counting objects:2131, done
    18. remote: Finding sources:100% (211/211)
    19. fatal: unable to access'https://android.googlesource.com/platform/art/': Failed to connect to android.googlesource.com port443: Connection refused
    20. fatal: unable to access'https://android.googlesource.com/platform/external/owasp/sanitizer/': Failed to connect to android.googlesource.com port443: Connection refused

    现在是实在没办法了,只能不断尝试以下步骤

    $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    $ chmod a+x ~/bin/repo
    $ mkdir WORKING_DIRECTORY
    $ cd WORKING_DIRECTORY
    $ repo init -u https://android.googlesource.com/platform/manifest
    $ repo sync

    终于能正常显示下载

    过一会VPN又断开了,等买了VPN再试

    待续............................

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值