配置android环境以及下载android源代码

来源:互联网 发布:淘宝买家注册流程 编辑:程序博客网 时间:2024/05/29 19:36

一、Installing JDK 

android 12.04环境下编译Android 4.4的代码还是需要JDK6的,方法如下:

1. 首先在Orecal官网下载JDK:

http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html

32位系统下载jdk-6u45-linux-x86,64位系统下载jdk-6u45-linux-x64

2. 创建jvm文件夹

sudo mkdir /usr/lib/jvm

3. 安装JDK6

sudo cp jdk-6u45-linux-x64.bin /usr/lib/jvm/sudo chmod +x jdk-6u45-linux-x64.binsudo ./jdk-6u45-linux-x64.bin

4. 设置环境变量

sudo mv jdk1.6.0_45/ jdk6export JAVA_HOME=/usr/lib/jvm/jdk6export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/libexport PATH=${JAVA_HOME}/bin:$PATH

5. 使能环境变量

source ~/.bashrc

6. 设置JDK6为系统默认JDK

因为在ubuntu中默认JDK可能是OpenJDK,这里我们设置JDK6为我们默认的JDK

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk6/bin/java 300sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk6/bin/javac 300
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk6/bin/javap 300
sudo update-alternatives --config java

7. 至此JDK就安装好了,现在就可以在shell中查看Java版本

java -version

二、Installing required packages (Ubuntu 12.04)
$ 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$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
libgl1-mesa-glx:i386 推荐 libgl1-mesa-dri:i386

但是在安装过程中遇到了如下错误:

Errors were encountered while processing:libc6-dev:i386 E: Sub-process /usr/bin/dpkg returned an error code (1)

解决方法如下:

$ sudo apt-get install linux-libc-dev:i386$ sudo apt-get install libc6-dev:i386

三、Configuring USB Access

The recommended approach is to create a file /etc/udev/rules.d/51-android.rules (as the root user) and to copy the following lines in it. <username> must be replaced by the actual username of the user who is authorized to access the phones over USB.

# adb protocol on passion (Nexus One)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"# fastboot protocol on passion (Nexus One)SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"# adb protocol on crespo/crespo4g (Nexus S)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"# fastboot protocol on crespo/crespo4g (Nexus S)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"# adb protocol on stingray/wingray (Xoom)SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"# fastboot protocol on stingray/wingray (Xoom)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"# adb protocol on maguro/toro (Galaxy Nexus)SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"# fastboot protocol on maguro/toro (Galaxy Nexus)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"# adb protocol on panda (PandaBoard)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"# adb protocol on panda (PandaBoard ES)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="<username>"# fastboot protocol on panda (PandaBoard)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"# usbboot protocol on panda (PandaBoard)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"# usbboot protocol on panda (PandaBoard ES)SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"# adb protocol on grouper/tilapia (Nexus 7)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="<username>"# fastboot protocol on grouper/tilapia (Nexus 7)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="<username>"# adb protocol on manta (Nexus 10)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="<username>"# fastboot protocol on manta (Nexus 10)SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="<username>"

五、Installing Repo

  1. Git Preparation works
    1. Install ssh and related packages.
    $ sudo apt-get install ssh
    Apply an account in${sh-git-server}
    Enable password-less SSHauthentication
    Assuming that you have an account magicyu for the Git server.
    Createa RSA key on your development machine:
    $ ssh-keygen -trsa
    $ { the keys should be generated at~/.ssh/id_rsa and ~/.ssh/id_rsa.pub}the application would prompt you to enter apassphrase, pleaseDO NOT enterany password.
    If you want to enable a more securepassword-less authentication, please checkhttp://www.ibm.com/developerworks/library/l-keyc2/ about using ssh-agent.
    For example:
    magicyu@magicyu-desktop:~$ssh-keygen  -t rsa
    Generating public/private dsa keypair.
    Enter file in which to save the key(/home/magicyu/.ssh/id_rsa):
    Enter passphrase (empty for nopassphrase):
    Enter same passphrase again:
    Your identification has been saved in/home/magicyu/.ssh/id_rsa.
    Your public key has been saved in/home/magicyu/.ssh/id_rsa.pub.
    The key fingerprint is:
    96:f6:4a:10:9f:98:5e:e0:1d:f9:a1:d9:c8:bb:64:e7magicyu@magicyu-desktop
    The key's randomart image is:
    +--[ DSA 1024]----+
    |                 |
    |         .      |
    |     o o .      |
    |    . O X .     |
    |     = S o      |
    |    . = o       |
    |     . = o      |
    |       + =      |
    |        o E     |
    +-----------------+
    Copy the RSA public key to shgit              ssh-add   ~/.ssh/id_rsa
    $ scp~/.ssh/id_rsa.pub magicyu@shgit.com:~/.ssh/authorized_keys
    You may need tossh to shgit.com to create a .ssh folder firstly for yourself.  $ ssh magicyu@shgit.com $mkdir .ssh
    For example: scp ~/.ssh/id_rsa.pubmagicyu@shgit.com:~/.ssh/authorized_keys

    Now, the RSAauthentication has been enabled. You can give it a try by: $ sshmagicyu@$shgit.com. This time it won't prompt you with the password.
    Tips: If you want to log on the gitserver with your ID on different hosts, you just need to create RSA file foreach host and cat it to the original one on the server.
    Setthe default login user
    If the login user is not specified in URL,ssh uses the current user name as the login user. If you use the same user namein your development machine andshgit.marvell.com, there won't be any problem. But if not, youneed edit the ssh configure file to specify the default login user. on yourdevelopment machine:
    $ vim ~/.ssh/config $ {add the followinglines}
    Host shgit.marvell.com
    User <your user name onshgit.com >
    For example:
    Hostshgit..com
    User magicyu

  2. First, ensure you have a GIT. Then make sure you have a bin/ directory in your home directory and that it is included in your path:

    $ sudo apt-get install git-core
  3. $ mkdir ~/bin$ PATH=~/bin:$PATH
  4. Download the Repo tool and ensure that it is executable:
  5. $ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo(会报错)
  6. $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo(这个地址没有问题)$ chmod a+x ~/bin/repo

五、Initializing a Repo client


After installing Repo, set up your client to access the Android source repository:

  1. Create an empty directory to hold your working files. If you're using MacOS, this has to be on a case-sensitive filesystem. Give it any name you like:

    $ mkdir WORKING_DIRECTORY$ cd WORKING_DIRECTORY
  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, which specifies where the various repositories included in the Android source will be placed within your working directory.

    $ repo init -u https://android.googlesource.com/platform/manifest

    To check out a branch other than "master", specify it with -b:

    $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1(官网版)
  3. $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.4_r1.2(我下的4.4版)
  4. When prompted, configure Repo with your real name and email address. To use the Gerrit code-review tool, you will need an email address that is connected with a registered Google account. Make sure this is a live address at which you can receive messages. The name that you provide here will show up in attributions for your code submissions.

A successful initialization will end with a message stating that Repo is initialized in your working directory. Your client directory should now contain a .repo directory where files such as the manifest will be kept.

六、Downloading the Android Source Tree


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

$ repo sync
七、重启电脑可能报错:出现“Could not write bytes: broken pipe”
开机出现logo后长按左shift键,进入安全模式,
参考:http://blog.sina.com.cn/s/blog_60f9c0050101eoch.html和http://blog.csdn.net/yhm18ke/article/details/18400677解决
0 0
原创粉丝点击