为了建立android的开发环境,刚安装了一个Ubuntu 10.10 32-bit,记录下建立android 2.2开发环境的过程和解决的问题。
http://blog.csdn.net/l_serein/article/details/6415861
准备下载环境
参照官方网站准备下载环境
- $ sudo apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev valgrind
准备JDK和Eclipse
froyo最新版的build已经不需要JDK1.5了,直接下载一个linux 32-bit的JDK1.6就行。不太喜欢Ubuntu支持JDK/Eclipse带来的新问题,因此直接下载jdk-6u22-linux-i586.bin并在/opt目录运行安装,为了简单,我把安装后的目录换名jdk1.6。
Eclipse一定要下载Java EE版本,因为ADT插件的build需要。我下载的是3.5.2的Eclipse包eclipse-jee-galileo-SR2-linux-gtk.tar.gz。同样展开在/opt目录,方法就不赘述了。
修改/etc/environment并重新登录:
- $ sudo ln -s /opt/eclipse/eclipse /usr/bin/eclipse
- $ sudo vi /etc/environment
- PATH = "/opt/jdk1.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
- JAVA_HOME =/opt/jdk1.6
- JAVA_BIN =/opt/jdk1.6/bin
- CLASSPATH =/opt/jdk1.6/lib/dt.jar:/opt/jdk1.6/lib/tools.jar
- ECLIPSE_HOME =/opt/eclipse
下载Android源码
按照官方网页http://source.android.com/source/download.html指导下载Android源码,也不赘述。
- $ sudo curl http://android.git.kernel.org/repo > /bin/repo
- $ sudo chmod a+x /bin/repo
我是在/work文件系统中建立android下载目录的,注意这里最好有10GB以上剩余空间。
- $ sudo mkdir /work/android
- $ sudo chown carl /work/android
- $ cd /work/android
- $ repo init -u git://android.git.kernel.org/platform/manifest.git
- $ repo sync
编译Android SDK
Android 2.2源码直接支持JDK1.6和64-bit Linux,反而32-bit Linux还需要手工修改一些文件。错误如下
Only 64-bit build environments are supported beyond froyo/2.2.
修改方法具体请参阅
http://limssb.blog.163.com/blog/static/14730437201093092640133/
为方便,下面转载如下
- project build/
- diff --git a/core/main.mk b/core/main.mk
- index f761ba5..4ee4bf9 100644
- --- a/core/main.mk
- +++ b/core/main.mk
- @@ -68,7 +68,7 @@ $(info Checking build tools versions...)
- ifeq ($(BUILD_OS),linux)
- build_arch : = $(shell uname -m)
- -ifneq (64,$(findstring 64,$(build_arch)))
- +ifneq (i686,$(findstring i686,$(build_arch)))
- $(warning ************************************************************)
- $(warning You are attempting to build on a 32-bit system.)
- $(warning Only 64-bit build environments are supported beyond froyo/2.2.)
- project external/clearsilver/
- diff --git a/cgi/Android.mk b/cgi/Android.mk
- index 21c534b..37b8246 100644
- --- a/cgi/Android.mk
- +++ b/cgi/Android.mk
- @@ -13,8 +13,8 @@ LOCAL_C_INCLUDES : = $(LOCAL_PATH)/..
- LOCAL_CFLAGS : = -fPIC
- # This forces a 64-bit build for Java6
- -LOCAL_CFLAGS += -m64
- -LOCAL_LDFLAGS += -m64
- +LOCAL_CFLAGS += -m32
- +LOCAL_LDFLAGS += -m32
- LOCAL_NO_DEFAULT_COMPILER_FLAGS : = true
- diff --git a/cs/Android.mk b/cs/Android.mk
- index 9f0e30a..275845d 100644
- --- a/cs/Android.mk
- +++ b/cs/Android.mk
- @@ -9,8 +9,8 @@ LOCAL_C_INCLUDES : = $(LOCAL_PATH)/..
- LOCAL_CFLAGS : = -fPIC
- # This forces a 64-bit build for Java6
- -LOCAL_CFLAGS += -m64
- -LOCAL_LDFLAGS += -m64
- +LOCAL_CFLAGS += -m32
- +LOCAL_LDFLAGS += -m32
- LOCAL_NO_DEFAULT_COMPILER_FLAGS : = true
- diff --git a/java-jni/Android.mk b/java-jni/Android.mk
- index 21b4fd1..c1d38d2 100644
- --- a/java-jni/Android.mk
- +++ b/java-jni/Android.mk
- @@ -34,8 +34,8 @@ LOCAL_C_INCLUDES : = /
- LOCAL_CFLAGS += -fPIC
- # This forces a 64-bit build for Java6
- -LOCAL_CFLAGS += -m64
- -LOCAL_LDFLAGS += -m64
- +LOCAL_CFLAGS += -m32
- +LOCAL_LDFLAGS += -m32
- LOCAL_NO_DEFAULT_COMPILER_FLAGS : = true
- diff --git a/util/Android.mk b/util/Android.mk
- index 386f379..b694ef4 100644
- --- a/util/Android.mk
- +++ b/util/Android.mk
- @@ -18,8 +18,8 @@ LOCAL_C_INCLUDES : = $(LOCAL_PATH)/..
- LOCAL_CFLAGS : = -fPIC
- # This forces a 64-bit build for Java6
- -LOCAL_CFLAGS += -m64
- -LOCAL_LDFLAGS += -m64
- +LOCAL_CFLAGS += -m32
- +LOCAL_LDFLAGS += -m32
- LOCAL_NO_DEFAULT_COMPILER_FLAGS : = true
编译SDK并配置环境
如下就是编译SDK
- $ cd / work /android
- $ make sdk
编译完后会在out/host/linux-x86/sdk目录下生成一个zip文件,我的是android-sdk_eng.carl_linux-x86.zip。展开到/opt目录下并配置环境
- $ sudo unzip -e /work/android/out/host/linux-x86/sdk/android-sdk_eng.carl_linux-x86.zip
- $ sudo chown -R carl android-sdk_eng.carl_linux-x86/
- $ sudo vi /etc/environment
- PATH = "/opt/android-sdk_eng.carl_linux-x86/tools:/opt/sdk/android-sdk_eng.carl_linux-x86/platform-tools:/opt/jdk1.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
重新登录下。
编译ADT
我下载的android 2.2源码中有个问题,编译ADT插件的时候会出错,修改sdk/eclipse/scripts目录下的build_plugins.sh即可。原来的CONFIG_DIR目录会/work/android并列目录下生成out,产生权限问题。
- $ vi / work /android/sdk/eclipse/scripts/build_plugins.sh
- ...
- CONFIG_DIR="../../out/eclipse-configuration-$BUILD_VERSION"
- ...
如下可以编译Eclipse插件
- $ mkdir ~/adt
- $ cd /work /android/sdk/eclipse/scripts
- $ ./build_server.sh ~/adt
在~/adt目录下生成了Eclipse插件包android-eclipse-v201011020546.zip。
安装Eclipse插件
Help->Install New Software选取Archive...参见下图安装Eclipse插件(添加链接)
至此Android编译开发环境全部完成。