搭建android开发环境

来源:互联网 发布:好听的网络红歌 编辑:程序博客网 时间:2024/05/16 19:26

一. Initializing a Build Environment

    

Setting up a Linux build environment

     Detailed instructions for Ubuntu and MacOS follow. In general you will need:

  • Python 2.6 -- 2.7, which you can download from python.org.

  • GNU Make 3.81 -- 3.82, which you can download from gnu.org,

  • JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both from java.sun.com.

  • Git 1.7 or newer. You can find it at git-scm.com

     
     Installing the JDK

The Sun JDK is no longer in Ubuntu's main package repository. In order to download it, you need to add the appropriate repository and indicate to the system which JDK should be used.

Java 6: for Gingerbread and newer

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
jdk-6u45-linux-x64.bin
1.安装JDK先增加执行权限:sudo chmod 777 jdk-6u45-linux-x64.bin新建一个文件夹:sudo mkdir /opt/java "这个是要注意的,因为intel lij 对路径的识别只支持三个路径,所有,要把JDK安装在这三个之一:/usr/java or /opt/java or/usr/lib/jvm 我就在这出了一个问题移动到要安装的目录:sudo mv jdk-6u45-linux-x64.bin /opt/java         sudo /opt/java/jdk-6u45-linux-x64.bin这个安装包的任务完成了,扫扫:sudo rm -f /opt/java/jdk-6u45-linux-x64.bin2.配置JDKsudo gedit ~/.bashrc 加上:#set java environmentexport JAVA_HOME=/opt/java/jdk1.6.0_45export JRE_HOME=$JAVA_HOME/jreexport CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/libexport PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME/lib:$JAVA_HOMEsudo gedit /etc/environment 加上:   JAVA_HOME=/opt/java/jdk1.6.0_45 ”这个是我遇到第二个问题,不知道什么原因,最开始我是在/etc/profile配置额上边~/.bashrc加的那段,
就是不行,找不到JAVA_HOME这个项,就直接放到这个文件了一份,ANDROID STUDIO就可以启动了。 
之后又吧/etc/profile的配置项挪到了~/.bashrc了, 我还很小白,现在还不知道是什么原因导致不能读到/etc/profile的配置项,
猜测可能是没更新环境变量?有知道的帮忙回一下。

linux配置java环境变量三种方法

1. 修改/etc/profile文件
如果你的计算机仅仅作为开发使用时推荐使用这种方法,因为所有用户的shell都有权使用这些环境变量,可能会给系统带来安全性问题。
·用文本编辑器打开/etc/profile
·在profile文件末尾加入:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
·重新登录
·注解
a. 你要将 /usr/share/jdk1.6.0_14改为你的jdk安装目录
b. linux下用冒号“:”来分隔路径
c. $PATH / $CLASSPATH / $JAVA_HOME 是用来引用原来的环境变量的值,在设置环境变量时特别要注意不能把原来的值给覆盖掉了,这是一种 常见的错误。
d. CLASSPATH中当前目录“.”不能丢,把当前目录丢掉也是常见的错误。
e. export是把这三个变量导出为全局变量。
f. 大小写必须严格区分。

2. 修改.bash_profile文件
这种方法更为安全,它可以把使用这些环境变量的权限控制到用户级别,如果你需要给某个用户权限使用这些环境变量,你只需要修改其个人用户主目录下的.bash_profile文件就可以了。
·用文本编辑器打开用户目录下的.bash_profile文件
·在.bash_profile文件末尾加入:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
·重新登录

3. 直接在shell下设置变量
不赞成使用这种方法,因为换个shell,你的设置就无效了,因此这种方法仅仅是临时使用,以后要使用的时候又要重新设置,比较麻烦。
只需在shell终端执行下列命令:
export JAVA_HOME=/usr/share/jdk1.6.0_14
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
·重新登录


Installing required packages (Ubuntu 12.04)


You will need a 64-bit version of Ubuntu. Ubuntu 12.04 is recommended. Building using an older version of Ubuntu is not supported on master or recent releases.

$ 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
 

The GUI won't start initialized the build environment for Android
My laptop worked perfectly util I initialized the build environment for Android. The GUI won't start. 
It looks like some kinds of graphics card problems. I tried to fix it but after trying a lot of solutions 
on the internet nothing worked. (I only know basic linux stuffs.) I've already reinstalled the OS. However,
I still want to build the Android from source.

Any idea what might cause the problem? any workaround?

Here is the command that I used to initialize the build environment:

$ 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

My laptop model is asus u36sd. (https://help.ubuntu.com/community/Asus_U36SD) Thanks

Edit: Base on this, I guess libgl1-mesa-glx:i386 might cause the issue.

sudo apt-get install libgl1-mesa-dri:i386The following packages will be REMOVED:libgl1-mesa-dri-lts-quantal libxatracker1-lts-quantal ubuntu-desktop xorgxserver-xorg-lts-quantal xserver-xorg-video-all-lts-quantalxserver-xorg-video-vmware-lts-quantalThe following NEW packages will be installed:libdrm-intel1:i386 libdrm-nouveau1a:i386 libdrm-radeon1:i386 libdrm2:i386libexpat1:i386 libffi6:i386 libgl1-mesa-dri:i386 libllvm3.0:i386libpciaccess0:i386 libstdc++6:i386
Google 官方要求的包里面有:$ 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其中的libgl1-mesa-glx:i386会提示找不到,会提示安装一个libgl1-mesa-dri:i386 。装完以后会提示说:sudo apt-get install libgl1-mesa-dri:i386The following packages will be REMOVED:libgl1-mesa-dri-lts-quantal libxatracker1-lts-quantal ubuntu-desktop xorgxserver-xorg-lts-quantal xserver-xorg-video-all-lts-quantalxserver-xorg-video-vmware-lts-quantalThe following NEW packages will be installed:libdrm-intel1:i386 libdrm-nouveau1a:i386 libdrm-radeon1:i386 libdrm2:i386libexpat1:i386 libffi6:i386 libgl1-mesa-dri:i386 libllvm3.0:i386libpciaccess0:i386 libstdc++6:i386也就是说Xorg没有了。当时每台注意这些内容,正常编译,很顺利。重启的时候发现木有图形界面,ctrl + alt + F1可以进入终端的,然后完全删除了Xorg,重新apt-get install安装了X,这时候会提示卸载libgl1-mesa-dri:i386,不管了卸载就卸载了。可是这样不就造成了一个死循环了嘛。。我想编译的时候就再来装libgl1-mesa-dri:i386,重启一下又要重新安装xorg??
Ubuntu 12.04关于libgl1-mesa-glx:i386安装的问题        打算封装一个集成Android开发环境的Ubuntu 12.04的LiveCD.在安装Android源码环境的时候遇到了其他人一样的问题, libgl1-mesa-glx:i386 装不上.我用的是12.04.2的iso.下面是安装信息:    shaka@Shaka:~$ sudo apt-get install libgl1-mesa-glx:i386<br />Reading package lists... Done<br />Building dependency tree &nbsp; &nbsp; &nbsp;&nbsp;<br />Reading state information... Done<br />Some packages could not be installed. This may mean that you have<br />requested an impossible situation or if you are using the unstable<br />distribution that some required packages have not yet been created<br />or been moved out of Incoming.<br />The following information may help to resolve the situation:<br />The following packages have unmet dependencies:<br />&nbsp;libgl1-mesa-glx:i386 : Depends: libglapi-mesa:i386 (= 8.0.4-0ubuntu0.6)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Recommends: libgl1-mesa-dri:i386 (>= 7.2)<br />E: Unable to correct problems, you have held broken packages.<br />shaka@Shaka:~$ sudo apt-get install libgl1-mesa-dri:i386<br />Reading package lists... Done<br />Building dependency tree &nbsp; &nbsp; &nbsp;&nbsp;<br />Reading state information... Done<br />The following packages were automatically installed and are no longer required:<br />&nbsp; x11-apps x11-session-utils x11-xfs-utils xinit<br />Use 'apt-get autoremove' to remove them.<br />The following extra packages will be installed:<br />&nbsp; libdrm-nouveau1a:i386 libllvm3.0:i386<br />Suggested packages:<br />&nbsp; libglide3:i386<br />The following packages will be REMOVED:<br />&nbsp; libgl1-mesa-dri-lts-quantal libgl1-mesa-dri-lts-quantal:i386 libxatracker1-lts-quantal ubuntu-desktop xorg xserver-xorg-lts-quantal<br />&nbsp; xserver-xorg-video-all-lts-quantal xserver-xorg-video-vmware-lts-quantal<br />The following NEW packages will be installed:<br />&nbsp; libdrm-nouveau1a:i386 libgl1-mesa-dri:i386 libllvm3.0:i386<br />0 upgraded, 3 newly installed, 8 to remove and 0 not upgraded.<br />Need to get 10.5 MB of archives.<br />After this operation, 12.4 MB of additional disk space will be used.<br />Do you want to continue [Y/n]?&nbsp;</p>        当我们安装libgl1-mesa-glx:i386的时候,他提示依赖 libgl1-mesa-dri:i386, 那我们就先装这个 libgl1-mesa-dri:i386.等等.这里先别着急,看看REMOVED选项,他要把带quantal的对应包全部卸载?看到quantal我就想到了quantal内核,12.10已经使用改内核,而ubuntu 12.04.2之后的iso(好像12.04.2的有两个镜像,前期的一个是没升级到 quantal内核的)镜像也升级到这个内核了.这个内核的很多包有个特点,都是加quantal后缀的.如果看过Ubunt 12.04内核升级到3.5.0-23的文章就会有所了解. How can I upgrade the Ubuntu 12.04.2 kernel to 3.5.0-23?        既然知道了这些,那说明我们要安装的并不是 libgl1-mesa-glx:i386,而是要安装对应的quantal版本,查了下,对应的名字是:libgl1-mesa-glx-lts-quantal:i386.        然后看看/usr/lib32/mesa/libGL.so.1是否存在,存在说明已经安装好了,按照Android官方说明,加一个软链接就行了:    sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so        -—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—-—        2013-12-30:        发现我机器上没的 /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so 这两个文件,编译android压根就没问题.看来这个软链接不是必要的    sudo find /usr/ -name libGL.so*    /usr/NX/scripts/vgl/libGL.so    /usr/lib/fglrx/libGL.so.1.2    /usr/lib/fglrx/libGL.so    /usr/lib/fglrx/libGL.so.1    /usr/lib/i386-linux-gnu/libGL.so    /usr/lib/i386-linux-gnu/mesa/libGL.so.1.2    /usr/lib/i386-linux-gnu/mesa/libGL.so.1    /usr/lib/x86_64-linux-gnu/libGL.so    /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2    /usr/lib/x86_64-linux-gnu/mesa/libGL.so    /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1    /usr/lib32/fglrx/libGL.so.1.2    /usr/lib32/fglrx/libGL.so.1        周末折腾,把内核升级到3.5了,发现已经不是quantal的内核了,安装的mesa又是 libgl1-mesa-glx:i386 了.所以具体安装那个得看内核,装对了就行了.用apt-get安装有提示卸载的时候要特别注意了. 

二.Downloading the Source

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 the Developingsection.

To install Repo:

  1. Make sure you have a bin/ directory in your home directory and that it is included in your path:

    $ mkdir ~/bin$ PATH=~/bin:$PATH
  2. Download the Repo tool and ensure that it is executable:

$ curl http://commondatastorage.googleapis.com/git-repo-downloads/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. 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

The Android source files will be located in your working directory under their project names. The initial sync operation will take an hour or more to complete. For more about repo sync and other Repo commands, see theDeveloping section.

1.下载repo$ mkdir ~/bin$ PATH=~/bin:$PATH$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo$ chmod a+x ~/bin/repo在实际下载时        $ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo下的是空的,原因网上有几种说法,总之是这个站点不能用,幸亏有位好心的大哥提供了一个      $ curl "http://php.webtutor.pl/en/wp-content/uploads/2011/09/repo" > ~/bin/repo记过这一步后在,repo就下载到了~/bin/ 下
在.repo目录下的找到fetch属性
改成
fetch="git://Android.git.linaro.org/"

三.Building the System

$ source build/envsetup.sh

or

$ . build/envsetup.sh
$ make -j4

0 0