Get source ?(Android Open Source Project?)

来源:百度文库 编辑:神马文学网 时间:2024/04/27 16:04:08

Get source

目录

  1. 1 What's in the source?
  2. 2 Setting up your machine
    1. 2.1 Linux
      1. 2.1.1 Ubuntu Linux (i386)
      2. 2.1.2 Ubuntu Linux (amd64)
      3. 2.1.3 Running Linux in a virtual machine
      4. 2.1.4 Other Linux
    2. 2.2 Mac OS
  3. 3 Installing Repo
  4. 4 Initializing a Repo client
  5. 5 Getting the files
  6. 6 Building the code
  7. 7 Using an IDE
  8. 8 Troubleshooting
  9. 9 What's next?
For information about current problems and fixes, see Known issues.
This document describes how to set up your local work environment, how to use Repo to get the Android files, and how to build the files on your machine.

Related reading:
  • For an overview of the entire code-review and code-update process, see Workflow.
  • For reference details about Repo, see Using Repo and Git.

For a description of all the projects that make up the Android source code, see Project layout. To see snapshots and histories of the files available in the public Android repositories, visit the GitWeb web interface.   The source is approximentely 2.1GB in size.  You will need 6GB free to complete the build.

To build the Android source files, you will need to use Linux or Mac OS. Building under Windows is not currently supported.

Linux

The Android build is routinely tested on recent versions of Ubuntu (6.06 and later), but reports of successes or failures on other distributions are welcome.

Ubuntu Linux (i386)

To set up your Linux development environment, make sure you have the following:
  • Git 1.5.4 or newer and the GNU Privacy Guard. 
$ sudo apt-get install git-core gnupg
  • JDK 5.0, update 12 or higher.
$ sudo apt-get install sun-java6-jdk
  • The following packages: flex, bison, gperf, libsdl-dev, libesd0-dev, libwxgtk2.6-dev (optional), build-essential, zip, curl.  
$ sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
  • You might also want Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc. 
$ sudo apt-get install valgrind
  • Intrepid (8.10) users may need a newer version of libreadline:
$ sudo apt-get install lib32readline5-dev

Ubuntu Linux (amd64)

This has not been as well tested. Please send success or failure reports to repo-discuss@googlegroups.com.
The Android build requires a 32-bit build environment as well as some other tools:
  • Git, JDK, flex, and the other packages as listed above in the i386 instructions:   
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl
  • Get a 32-bit version of the JVM:

    $ sudo apt-get install sun-java6-jdk       # JDK tools (javac, etc)
    $ sudo apt-get install ia32-sun-java6-bin  # JRE (java itself)
    $ sudo update-java-alternatives -s ia32-java-6-sun

  • Pieces from the 32-bit cross-building environment:
$ sudo apt-get install lib32z1-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs
  • Intrepid (8.10) users may need a newer version of libreadline:
$ sudo apt-get install lib32readline5-dev
  • X11:
    • Ubuntu doesn't have packages for the X11 libraries, but that can be worked around with the following command:

      $ sudo ln -s /usr/lib32/libX11.so.6 /usr/lib32/libX11.so

    • If the build fails because of missing X11/Xlib.h and X11/Xatom.h, install the X11 devel packages.  (This problem exists when building on Ubuntu 8.10 x86_64)

      sudo apt-get install x11proto-core-dev  # provides Xatom.h
      sudo apt-get install libx11-dev  # provides Xlib.h

Running Linux in a virtual machine

If you are running Linux in a virtual machine, you will need at least 1.5MB of RAM and 10GB or more of disk space in order to build the Android tree.

Other Linux

There's no reason why Android cannot be built on non-Ubuntu systems. Please send any success or failure reports to repo-discuss@googlegroups.com. In general you will need:

  • Python 2.4, which you can download from python.org 
  • JDK 5.0, update 12 or higher, which you can download from java.sun.com 
  • Git 1.5.4 or newer. You can find it at http://git.or.cz/ .

Anything missing from this list? Please let us know!


Mac OS

Requirements:

  • To build the Android files in a Mac OS environment, you need an Intel/x86 machine. The Android build system and tools do not support the obsolete PowerPC architecture.
  • Android must be built on a case-sensitive file system.
    • We recommend that you build Android on a partition that has been formatted with the "Case-sensitive Journaled HFS+" file system:
      • A case-sensitive file system is required because the sources contain files that differ only in case.
      • Journaled systems are more robust. (This is optional, but recommended.)
      • HFS+ is required to successfully build Mac OS applications such as the Android Emulator for OS X.
    • If you want to avoid partitioning/formatting your hard drive, you can use a case-sensitive disk image instead.
      • To create the image:
        • launch /Applications/Utilities/Disk Utility
        • select "New Image"
        • size: 8 GB (this will work, but you can choose more if you want to)
        • volume format: case sensitive, journaled
      • This will create a .dmg file which, once mounted, acts as a drive with the required formatting for Android development. For a disk image named "android.dmg" stored in your home directory, you can add the following to your ~/.bash_profile to mount the image when you execute "mountAndroid":

        # command to mount the android file image
        function mountAndroid  { hdiutil attach ~/android.dmg  -mountpoint /Volumes/android; }

        Once mounted, you'll do all your work in the "android" volume. You can eject it (unmount it) just like you would with an external drive.
    To set up your Mac OS development environment, follow these steps:
    1. Install the XCode version 2.4 or later from http://developer.apple.com . We recommend version 3.0 or newer.
    2. Install MacPorts. To do this:
      1. Download the tar file from http://www.macports.org/ and untar the files.
      2. Run the following:
          $ ./configure
          $ make
          $ sudo make install
      3. Make sure that /opt/local/bin is in your path before /usr/bin. by running
            $ echo $PATH
        If you don't see /opt/local/bin, edit $HOME/.bash_profile and add the line
          export PATH=/opt/local/bin:$PATH
        (or the equivalent for other shells) after any other PATH-related lines. To verify that your path is now correct, open a new terminal and run echo $PATH again.
      4. Ask MacPorts to update itself:
          $ sudo port selfupdate
    3. Get the following packages from port:
        $ POSIXLY_CORRECT=1 sudo port install gmake libsdl git-core gnupg
    4. Upgrade GNU make to 3.81 or later by running.  Mac OS doesn't come with a recent enough version.
        $ sudo ln -s gmake /opt/local/bin/make
    5. Set an appropriate per-process file descriptor limit. To do this, add the following lines to your .bash_profile file:
         # set the number of open files to be 1024
         ulimit -S -n 1024

    Installing Repo

    Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see Using Repo and Git.

    To install, initialize, and configure Repo, follow these steps:

    1. Make sure you have a ~/bin directory in your home directory, and check to be sure that this bin directory is in your path:
        $ cd ~
        $ mkdir bin
        $ echo $PATH
    2. Download the repo script and make sure it is executable:
      $ curl http://android.git.kernel.org/repo >~/bin/repo
      $ chmod a+x ~/bin/repo


    Initializing a Repo client

    1. Create an empty directory to hold your working files:
      $ mkdir mydroid
      $ cd mydroid
    2. Run repo init to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest:
      $ repo init -u git://android.git.kernel.org/platform/manifest.git
      • If you would like to check out a branch other than "master", specify it with -b, like:
        $ repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
    3. When prompted, configure Repo with your real name and email address. If you plan to submit code, use an email address that is associated with a Google account.
    A successful initialization will end with a message such as
       repo initialized in /mydroid

    Your client directory should now contain a .repo directory where files such as the manifest will be kept.

    What will my name and email be used for? 

    To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account (which does not have to be a Gmail address). Make sure this is a live address at which you can receive messages. The real name that you provide here will show up in attributions for your code submissions.

    What is a manifest file?

    The Android source files are divided among a number of different repositories. A manifest file contains a mapping of where the files from these repositories will be placed within your working directory when you synchronize your files.


    Getting the files

    To pull down files to your working directory from the repositories as specified in the default manifest, run

       $ repo sync 

    For more about repo sync and other Repo commands, see Using Repo and Git.

    The Android source files will be located in your working directory under their project names.

    Building the code

    To build the files, run make from within your working directory:
        $ cd ~/mydroid 
        $ make

    If your build fails, complaining about a missing "run-java-tool", try setting the ANDROID_JAVA_HOME env var to $JAVA_HOME before making.  E.g.,

        $ export ANDROID_JAVA_HOME=$JAVA_HOME

    Using an IDE

    • Using Eclipse for Android platform development

    Troubleshooting

    ImportError: No module named readline

    Mac users getting this should install Python 2.5.2.  

    Linux users that installed Python from source, make sure the dependencies for libreadline are installed, and rebuild Python.

    What's next?

    To learn about reporting an issue and searching previously reported issues, see Report bugs. For information about editing the files and uploading changes to the code-review server, see Contribute.