-
要想在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.0402. 需要有良好的网络支持才能使用,如果没网络下面的安装无法进行03. 按以下顺序安装组件04.05. 1、配置163的mirror06. 替换 /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 restricted12. deb-src http://mirrors.163.com/ubuntu/ precise main restricted13. deb http://mirrors.163.com/ubuntu/ precise-updates main restricted14. deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted15. deb http://mirrors.163.com/ubuntu/ precise universe16. deb-src http://mirrors.163.com/ubuntu/ precise universe17. deb http://mirrors.163.com/ubuntu/ precise-updates universe18. deb-src http://mirrors.163.com/ubuntu/ precise-updates universe19. deb http://mirrors.163.com/ubuntu/ precise multiverse20. deb-src http://mirrors.163.com/ubuntu/ precise multiverse21. deb http://mirrors.163.com/ubuntu/ precise-updates multiverse22. deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse23. deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse24. deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse25. deb http://mirrors.163.com/ubuntu/ precise-security main restricted26. deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted27. deb http://mirrors.163.com/ubuntu/ precise-security universe28. deb-src http://mirrors.163.com/ubuntu/ precise-security universe29. deb http://mirrors.163.com/ubuntu/ precise-security multiverse30. deb-src http://mirrors.163.com/ubuntu/ precise-security multiverse31. deb http://extras.ubuntu.com/ubuntu precise main32. deb-src http://extras.ubuntu.com/ubuntu precise main33.34. 2、apt-get update35.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:i38642.43. 提示:thismaby failed, install by error(apt-get install linux-libc-dev)44.45. sudo apt-get install xutils-dev46. sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1/usr/lib/i386-linux-gnu/libGL.so47.48. sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.8-dev49. sudo apt-get install build-essential zip curl libncurses5-dev zlib1g-dev tofrodos libglib2.0-dev50. 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 ~/bin2. $ PATH=~/bin:$PATH3. $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo4. $ 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/manifest02. 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 _Main06. repo._Run(argv)07. File"/home/android/android_source/.repo/repo/main.py", line125, in _Run08. cmd.Execute(copts, cargs)09. File"/home/android/android_source/.repo/repo/subcmds/init.py", line259, in Execute10. self._SyncManifest(opt)11. File"/home/android/android_source/.repo/repo/subcmds/init.py", line152, in _SyncManifest12. m.Sync_LocalHalf(syncbuf)13. File"/home/android/android_source/.repo/repo/project.py", line1045, in Sync_LocalHalf14. ifcommitter_email == self.UserEmail:15. File"/home/android/android_source/.repo/repo/project.py", line580, in UserEmail16. self._LoadUserIdentity()17. File"/home/android/android_source/.repo/repo/project.py", line584, in _LoadUserIdentity18. u = self.bare_git.var('GIT_COMMITTER_IDENT')19. File"/home/android/android_source/.repo/repo/project.py", line1772, in runner20. p.stderr))21. error.GitError: manifests var:22. *** Please tell me who you are.23.24. Run25.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/manifest02. .repo/manifests/: discarding159commits removed from upstream03.04. Your Name [dzt]:05. Your Email [dengzhangtai@gmail.com]:06.07. Your identity is: ls <dengzhangtai@gmail.com>08. isthiscorrect [y/n]? y09.10. Testing colorized output (for'repo diff','repo status'):11. black red green yellow blue magenta cyan white12. bold dim ul reverse13. Enable color display inthisuser account (y/n)? y14.15. repo initialized in /home/android/android_source01. root@ubuntu:/home/android/android_source# repo sync02. Fetching projects: 1% (2/172)03. Initializing project platform/bionic ...04. fatal:'../platform/bionic.git'does not appear to be a git repository05. fatal: Could not read from remote repository.06.07. Please make sure you have the correct access rights08. 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-toolsapt-get install phablet-tools
安装完还是不行,真没办法了,下个源码折腾个半天
再按这个步骤试下
1. $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo2. $ chmod a+x ~/bin/repo3. $ mkdir WORKING_DIRECTORY4. $ cd WORKING_DIRECTORY5. $ repo init -u https://android.googlesource.com/platform/manifest6. $ repo sync
居然又可以了,我一直都是连着VPN的。又报出如下问题
01. or: RPC failed; result=56, HTTP code =20002. error: RPC failed; result=56, HTTP code =20003. fatal: The remote end hung up unexpectedly04. fatal: early EOF05. fatal: index-pack failed06. fatal: The remote end hung up unexpectedly07. fatal: early EOF08. fatal: index-pack failed09. 1548.4M 157529k 0 0 9265 0 1:31:22 0:13:52 1:17:30 010. curl: (56) Recv failure: Connection timed out11. 988.8M 98424k 0 0 10366 0 2:29:46 0:13:52 2:15:54 012. curl: (56) Recv failure: Connection timed out13. remote: Sending approximately72.47MiB ...14. remote: Counting objects:25, done15. remote: Finding sources:100% (25/25)16. remote: Sending approximately47.99MiB ...17. remote: Counting objects:2131, done18. 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 refused20. 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再试
待续............................
搭建Ubuntu14.04编译环境并下载源码
最新推荐文章于 2024-03-08 17:37:09 发布