搭建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再试

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

posted on 2017-06-23 16:29  ljbguanli  阅读(585)  评论(0编辑  收藏  举报