Download Android source code based on ubuntu12.04

Source: Internet
Author: User
Tags gnupg
1. Install ubuntu12.04

I personally prefer to develop in windows, so I chose virtual box4.1.16 for Ubuntu installation. The specific methods for installing Ubuntu on a virtual machine are not described here, the only note is that the hard disk storage image is larger, and I open 60 Gb. It is best to select "Dynamic Storage Allocation ", this is because a large amount of space will be used to compile the android source code in the future, and an error will be reported if the space is insufficient for compilation.

After Ubuntu is installed, ensure that it can be connected to the Internet. Otherwise, subsequent steps cannot be performed.

2. Build the environment 1. Java environment

According to the practice on the Internet, most of them are installed through apt-get. I did not succeed, so I directly searched for Java using the software center that comes with ubuntu, select "openjdk Java 6 RunTime" and install it .. PS: version 6 or 5 is recommended, and version 7 may cause compilation errors.

After the installation is successful, enter:

[Plain]
View plaincopy
  1. Java-version

Command to view the version number. If the following prompt is displayed, the installation is successful.


2. Add the required package

Learn from the online methods.

64-bit system:

[Plain]
View plaincopy
  1. $ 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 g ++-multilib mingw32 tofrodos Python-markdown libgl1-mesa-dev unzip tproc

32-bit system:

[Plain]
View plaincopy
  1. $ Sudo apt-Get install Git-core GnuPG flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos Python-markdown libxml2-utils xsltproc

I am a 32-bit system, so select the second command and wait for it to automatically download and install.
3. Download Repo

Note: A lot of practices on the Internet are to use a proxy server for download. I started to try it. It is not only ineffective, but the request server has timed out. Finally, I deleted the environment variable for setting the proxy and immediately used it, the practice on the Internet is a bit redundant. Maybe the network environment is different. Try again.
In the user directory, create a bin folder to store the repo and set the path to the environment variable:

[Plain]
View plaincopy
  1. $ Mkdir ~ /Bin
  2. $ Path = ~ /Bin: $ path

Download the repo script to execute the repo.

[Plain]
View plaincopy
  1. $ Curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo> ~ /Bin/Repo
  2. $ Chmod A + x ~ /Bin/Repo
4. initialize a repo Client

Create an empty directory to store the android source code.

PS: do not include spaces in the directory name of the source code. Previously, my folder had spaces, so compilation failed.

I used Nautilus to create a directory in the root directory.
"Androiddev", and set users and groups as users that they often use, with read and write permissions.

Next, run repo in the directory created above to download the source code:

Download the main branch, which contains the latest modified bugs and does not officially release the latest source code.

[Plain]
View plaincopy
  1. $ Repo init-u https://android.googlesource.com/platform/manifest
Download other branches. For officially released versions, you can download them by running the "-B" command.

[Plain]
View plaincopy
  1. $ Repo init-u https://android.googlesource.com/platform/manifest-B android-4.0.1_r1

During the download process, you need to enter the name and email, and then select y for confirmation. Finally, the system prompts that repo Initialization is complete in the directory where it is located. Here we can also see a hidden file under the current directory. repo/
This file contains initialization information. 3. Execute the following command synchronously in the code

[Plain]
View plaincopy
  1. $ Repo sync

(If there is a new branch or new tag, it indicates that it is in the normal synchronization process.) at this time, you only need to wait for it to complete. This synchronization takes a long time, because all android code has been downloaded and other branches are included. The entire source code may be around 16 GB, but only waiting, but this time can be used to prepare the development environment.
 

A long download process may interrupt the download process. In this case, you need to re-repo sync to continue the synchronization. At the end of the download, there will be many prompts about the successful download of 100%,


The following errors are frequently prompted during code download:

Error: Failed connect to android.googlesource.com: 443; connection refused while accessinghttps: // android.googlesource.com/a/platform/frameworks/base/info/refs

Fatal: http request failed

Error: cannot fetch platform/tools/motodev

Error: cannot fetch platform/frameworks/base

Error: cannot fetch platform/prebuilts/SDK

Error: Exited sync due to fetch errors

Solution: edit the/etc/hosts file.

$ Vim/etc/hosts

Add and save the following content (save in advance ):

74.125.31.82 www.googlesource.com

74.125.31.82 android.googlesource.com

203.208.46.172 cache.pack.google.com

59.24.3.173cache.pack.google.com

Then enter again

$ Repo sync

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.