搭建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编译工具

Android环境搭建步骤Ubuntu14.04
需要有良好的网络支持才能使用,如果没网络下面的安装无法进行
按以下顺序安装组件

1、配置163的mirror
替换 /etc/apt/source.list中的源信息
sudo gedit /etc/apt/sources.list   //修改更新源设置

// 将以下地址加入到sources.list里面

deb http://mirrors.163.com/ubuntu/ precise main restricted
deb-src http://mirrors.163.com/ubuntu/ precise main restricted
deb http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb http://mirrors.163.com/ubuntu/ precise universe
deb-src http://mirrors.163.com/ubuntu/ precise universe
deb http://mirrors.163.com/ubuntu/ precise-updates universe
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe
deb http://mirrors.163.com/ubuntu/ precise multiverse
deb-src http://mirrors.163.com/ubuntu/ precise multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-security main restricted
deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted
deb http://mirrors.163.com/ubuntu/ precise-security universe
deb-src http://mirrors.163.com/ubuntu/ precise-security universe
deb http://mirrors.163.com/ubuntu/ precise-security multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-security multiverse
deb http://extras.ubuntu.com/ubuntu precise main
deb-src http://extras.ubuntu.com/ubuntu precise main

2、apt-get update

3、
sudo apt-get install git gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386

提示:this maby failed, install by error(apt-get install linux-libc-dev)

sudo apt-get install xutils-dev
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.8-dev
sudo apt-get install build-essential zip curl libncurses5-dev zlib1g-dev tofrodos libglib2.0-dev
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


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

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

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


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

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

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

root@ubuntu:/home/android/android_source# repo init -u https://android.googlesource.com/platform/manifest
Traceback (most recent call last):
  File "/home/android/android_source/.repo/repo/main.py", line 238, in <module>
    _Main(sys.argv[1:])
  File "/home/android/android_source/.repo/repo/main.py", line 220, in _Main
    repo._Run(argv)
  File "/home/android/android_source/.repo/repo/main.py", line 125, in _Run
    cmd.Execute(copts, cargs)
  File "/home/android/android_source/.repo/repo/subcmds/init.py", line 259, in Execute
    self._SyncManifest(opt)
  File "/home/android/android_source/.repo/repo/subcmds/init.py", line 152, in _SyncManifest
    m.Sync_LocalHalf(syncbuf)
  File "/home/android/android_source/.repo/repo/project.py", line 1045, in Sync_LocalHalf
    if committer_email == self.UserEmail:
  File "/home/android/android_source/.repo/repo/project.py", line 580, in UserEmail
    self._LoadUserIdentity()
  File "/home/android/android_source/.repo/repo/project.py", line 584, in _LoadUserIdentity
    u = self.bare_git.var('GIT_COMMITTER_IDENT')
  File "/home/android/android_source/.repo/repo/project.py", line 1772, in runner
    p.stderr))
error.GitError: manifests var: 
*** Please tell me who you are.

Run

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

to set your account's default identity.
Omit --global to set the identity only in this repository.

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"

初始化成功了

root@ubuntu:/home/android/android_source# repo init -u https://android.googlesource.com/platform/manifest
.repo/manifests/: discarding 159 commits removed from upstream

Your Name  [dzt]: 
Your Email [dengzhangtai@gmail.com]: 

Your identity is: ls <dengzhangtai@gmail.com>
is this correct [y/n]? y

Testing colorized output (for 'repo diff', 'repo status'):
  black    red      green    yellow   blue     magenta   cyan     white 
  bold     dim      ul       reverse 
Enable color display in this user account (y/n)? y

repo initialized in /home/android/android_source
正式下载源码,还是报错了

root@ubuntu:/home/android/android_source# repo sync
Fetching projects:   1% (2/172)  
Initializing project platform/bionic ...
fatal: '../platform/bionic.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
error: Cannot fetch platform/bionic

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

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

apt-get install phablet-tools

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

再按这个步骤试下

$ 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的。

又报出如下问题

or: RPC failed; result=56, HTTP code = 200
error: RPC failed; result=56, HTTP code = 200
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
 15 48.4M   15 7529k    0     0   9265      0  1:31:22  0:13:52  1:17:30     0
curl: (56) Recv failure: Connection timed out
  9 88.8M    9 8424k    0     0  10366      0  2:29:46  0:13:52  2:15:54     0
curl: (56) Recv failure: Connection timed out
remote: Sending approximately 72.47 MiB ...
remote: Counting objects: 25, done
remote: Finding sources: 100% (25/25)
remote: Sending approximately 47.99 MiB ...
remote: Counting objects: 2131, done
remote: Finding sources: 100% (211/211)
fatal: unable to access 'https://android.googlesource.com/platform/art/': Failed to connect to android.googlesource.com port 443: Connection refused
fatal: unable to access 'https://android.googlesource.com/platform/external/owasp/sanitizer/': Failed to connect to android.googlesource.com port 443: 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
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值