在Ubuntu 虚拟机上下载&编译android

在Ubuntu 虚拟机上下载&编译android

注意:

1. 网上关于编译android kernel 的文章很多。找资料时,应尽量找官方的权威资料。如果是随便在网上找到的一份文章(包括我写的这份),有可能误导人,按照上面说的一步一步做,最后还可能是失败(因为机器不同,配置不同等等),浪费了时间和精力。因此,要找靠谱的资料,最好到官方的网站上找。

总体来说,英文版的材料比中文的质量要好一些。

以下的过程,我根据的是 android 官网上的教程: http://source.android.com/source/initializing.html 来写的。

2. 找到这个教程后,先不急着动手,认真阅读完整个教程后再动手。Linux配置环境的一个很烦人的地方就在于,linux里太多packages, 而我们配置的环境往往是有版本限制的,如果上面说了是 1.7, 你下一个1.6或者1.8的版本都不行的,很可能出错,Linux就是这么抠门。

举一个例子,我第一眼看到这个教程的时候,没有认真阅读所有的文字,立即跟着教程一步一步地输入命令,安装到第4步的时候,才发现这个环境要求的是  64 位   Ubuntu 10.04系统,而我当时用的是Ubuntu 12.04. 上面说12.04这个版本还是experimental阶段,不保证能编译成功,就是有可能会编不过,浪费时间。为了一劳永逸一步到位,我不得不重新安装 64-bi Ubuntu 10.04系统,又从第一个步骤重头来过,很浪费时间。

教训就是,要认真教程,先了解 环境的明确的具体要求,再动手。造成这样的原因之一,就是教程的写作风格不同,作者的写作习惯不一样,有人喜欢把环境限制放在开头就说(这是比较有条理的好习惯),而有些作者(例如这个android build环境配置教程的作者)就喜欢把限制放在文章中间,等到我们执行若干个步骤后才可能发现我们的配置有误。

3. 备份一个干净的ubuntu 10.04。 干净的备份会让我们放心大胆地做试验,不行了就倒回去,省时省力。


以下是我的配置过程(英文); 

Step 1. Pre-process: install a virtual machine Ubuntu 10.04 

 install a new 64-bit Ubuntu 10.04 VM  in vmware. 
  1. install a ubuntu 10.04, (120G hard drive, 2G memory/RAM, vmware tools, keep it in a single file instead of multiple files.)
  2. update all packages  (this is IMPORTANT, because the newly installed Ubuntu is raw)
(为了避免下次再重用这个ubuntu, 我把那个虚拟机文件拷下来,下次再重用)

  1. check all versions required packages: git, jdk, python, openssl, take notes (该步可以跳过,只是想了解一台新安装的干净的Ubuntu 10.04 里的package 都是什么版本)
We can run below commands to check the version of these packages: 

python --version
java --version
make -v
git --version
openssl --version

以下是结果:
python: 2.6.5.  with openssl support. 
no jdk
GNU make 3.8.1
no git
OpenSSL 0.9.8k

According to the required packages listed in ( http://source.android.com/source/initializing.html)  , 

we need jdk 6 and git 1.7. Our result shows that python: 2.6.5 is fine

Step 2. install all required software & packages

1. install jdk 6:  sudo apt-get install openjdk-6-jdk openjdk-6-jre


here, maybe this is important :
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
( Magically, Git 1.8 works)

3. installed all required packages.  

using command: 

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 xsltproc

5. install repo
$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

6. mkdir under the same repository with repo. 

$ mkdir android1
$ cd android1

7.  before repo init, set my account name first: 

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


follow the next steps described in  http://source.android.com/source/initializing.html

最后,我的机器还不一定编译得过,因为教程上说 用virtual machine 编的话,至少要16G RAM/swap,而我只给了2G,有可能不够用,我暂时还没试过。

不过,这是硬件配置问题了,不是软件配置问题了,加个内存条或者换到一台高配置的机器里重复上述步骤,应该可以解决。

FAQ: 

Q1. repo init error:

if you encounter this error: 

repo init -u  https://android.googlesource.com/platform/manifest  
fatal: Cannot get  https://android.googlesource.com/tools/repo/clone.bundle  
fatal: error unknown url type: https 

My answer to Q1:

 Probably there was something MESSED UP with your installed python (2.6 or 2.7 or 3.3).  This is a tricky problem. I've spent nearly one entire day and tried many approaches listed in below URLs.  


They ALL FAILED.  I figure out it was impossible to figure out the reasons in my dirty old Ubuntu 10.04 environment.   so I re-installed a new, clean  Ubuntu 10.04 VM and followed the process described above. And it worked.  

中文版的注:如果遇到像  error unknown url type: https ,很有可能是python的版本有问题,我试过用整整一天去解决这个问题,但失败了,很沮丧。

我后来重新装ubuntu 10.04,在一台干净的机器上一步一步地试,按照我说的以上步骤一步一步地装,这样才解决了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值