下载配置好所有需要的工具以后开始下载android源代码跟编译自己的代码
创建下载目录android并初始化repo
~$ mkdir android
~$ cd android/
初始化
~/android$ repo init -u https://android.googlesource.com/platform/manifest
~/android$ repo init -u https://android.googlesource.com/platform/manifest -b android-2.3.1_r1
下载(慢慢等吧)
~/android$ repo sync
注意:最好是把自己创建的下载目录下面的.repo 里面manifest.xml属性fetch改为:fetch= "https://android.googlesource.com/"
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
此错误忽略,不影响编译
错误:/bin/bash: prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc: No such file or directory
解决方法:apt-get install lib32z1-dev
错误:/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
错误: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 -lncurses
解决方法:sudo apt-get install lib32ncurses5-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
ubuntu 10.04,默认的gcc版本为4.4,gcc-4.4太严格,有可能要从gcc-4.4降到gcc- 4.3
1、安装gcc-4.3
$ sudo apt-get install gcc-4.3 g++-4.3
2、修gcc相关链接
$ cd /usr/bin
$sudo ln -snf gcc-4.3 gcc
$sudo ln -snf g++-4.3 g++
$sudo ln -snf cpp-4.3 cpp
3、64bit系统需装如下包
$ sudo apt-get install g++-multilib g++-4.3-multilib
中间或许还有其他各种错误,遇到了自己百度去。
编译成功会有如下输出
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
解决方法:编辑 /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"
注:/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))
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