一、Android源码下载与编译
基于VMware 7.0 、ubuntu10.04 64位
1、Git工具。
若无则安装 ~$ sudo apt-get install git-core gnupg
2、Java sdk 。
~$ sudo add-apt-repository ppa:ferramroberto/java
~$ sudo apt-get update
~$ sudo apt-get install sun-java6-jre sun-java6-plugin
~$ sudo apt-get install sun-java6-jdk
另:接受安装条件时,tab键切换焦点。
3、安装其他需要的命令
~$ sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl
4、调试工具
~$ sudo apt-get install valgrind
5、安装repo工具
~$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
~$ chmod a+x ~/bin/repo
~$ chmod a+x ~/bin/repo
修改文件.bashrc
~$ vi .bashrc
在最后一行加入 export PATH=$PATH:~/bin
保存,执行 ~$ ./.bashrc
6、创建下载目录android并初始化repo
~$ mkdir android
~$ cd android/
初始化
~/android$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.1_r1
下载(慢慢等吧)
~/android$ repo sync
7、编译(这里也慢慢等)
~/android$ make
注意:
出现错误,首先,全部赋予可执行权限
错误:find: `frameworks/base/frameworks/base/docs/html': No such file or directory
find: `out/target/common/docs/gen': No such file or directory
find: `out/target/common/docs/gen': No such file or directory
此错误忽略,不影响编译
错误:/usr/include/gnu/stubs.h:7: fatal error: gnu/stubs-32.h: No such file or directory
解决方法: ~/android$ sudo apt-get install libc6-dev-i386
解决方法: ~/android$ sudo apt-get install libc6-dev-i386
错误:external/clearsilver/cgi/cgi.c:22: fatal error: zlib.h: No such file or directory
解决方法:~/android$ sudo apt-get install zlib1g-dev
错误:/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp] Error 1
解决方法:~/android$ sudo ln -s /usr/lib32/libstdc++.so.6 /usr/lib32/libstdc++.so
中间或许还有其他各种错误,遇到了自己百度去。
编译成功会有如下输出
Target system fs image:
out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Target ram disk: out/target/product/generic/ramdisk.img
Target userdata fs image: out/target/product/generic/userdata.img
Installed file list: out/target/product/generic/installed-files.txt
8、运行
启动模拟器,运行$ emulator
错误:No command 'emulator' found, did you mean:
Command 'qemulator' from package 'qemulator' (universe)
emulator: command not found
Command 'qemulator' from package 'qemulator' (universe)
emulator: command not found
解决方法:编辑 /etc/environment
加入环境变量
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:usr/lib/jvm/java-6-sun-1.6.0.26/bin:/home/nanlus2/android/out/host/linux-x86/bin"
CLASSPATH="/usr/lib/jvm/java-6-sun-1.6.0.26/lib"
JAVA_HOME="usr/lib/jvm/java-6-sun-1.6.0.26"
ANDROID_PRODUCT_OUT="/home/nanlus2/android/out/target/product/generic"
CLASSPATH="/usr/lib/jvm/java-6-sun-1.6.0.26/lib"
JAVA_HOME="usr/lib/jvm/java-6-sun-1.6.0.26"
ANDROID_PRODUCT_OUT="/home/nanlus2/android/out/target/product/generic"
注:/home/nanlus2/android为源码目录
保存,重启。运行$ emulator
错误:SDL init failure, reason is: No available video device
解决方法:$ apt-get install ia32-libs lib32stdc++6
再次运行$ emulator
成功
二、编译自己的apk
1、编写完成工程。
2、编写Android.mk文件,放入工程目录下
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := helloworld
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := helloworld
LOCAL_CERTIFICATE := platform
include $(BUILD_PACKAGE)
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
3、编译
拷贝工程至packages/apps/下
~$ cp -ri helloworld ~/android/packages/apps/helloworld
进入目录 ~/...../helloworld$ mm
编译成功:out/target/product/product_name/system/app/helloworld.apk
4、运行
安装在机子上运行之。 adb install xxx/helloworld.apk
在这里也可以一起打包,
$ make snod
然后,再运行,启动模拟器即可。