系统:Ubuntu 12.04 64

下载的步骤很简单,其实就官方那几步,

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir WORKING_DIRECTORY
$ cd WORKING_DIRECTORY

下载最新的代码:

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

指定下载的版本:

$ repo init -u https://android.googlesource.com/platform/manifest -b android-x.y.z_r1

开始下载:

$ repo sync

但是,有多少人能依上面方法,顺利地下载完成?!!

反正我没有!

下面是我遇到的问题:

1》repo用终端就下载不了

    解决办法是,自己手动去下载,放到~/bin/目录下,其实,也可以放到/bin/目录。记得加权限哦。

2》执行下载命令时报错:

fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle  
fatal: error [Errno 101] Network is unreachable

后来google到一种方法:

打开https://android.googlesource.com/new-password,用gmail帐号登录。然后,当然是点击接受啦

按照上面的说明,将对应的内容加到~/.netrc文件结尾,如果没有这个文件,可以手动创建。

然后再执行:

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

接着再执行上面的下载源码命令:

$ repo init -u https://android.googlesource.com/platform/manifest -b android-x.y.z_r1
$ repo sync

最后是漫长的等待,如果中途中断了,只要再执行repo sync
 

将近两天才下载完!

* [new tag]         android-4.4.2_r2 -> android-4.4.2_r2
 * [new tag]         android-4.4_r0.7 -> android-4.4_r0.7
 * [new tag]         android-4.4_r0.8 -> android-4.4_r0.8
 * [new tag]         android-4.4_r0.9 -> android-4.4_r0.9
 * [new tag]         android-4.4_r1 -> android-4.4_r1
 * [new tag]         android-4.4_r1.1 -> android-4.4_r1.1
 * [new tag]         android-4.4_r1.2 -> android-4.4_r1.2
 * [new tag]         android-cts-2.2_r8 -> android-cts-2.2_r8
 * [new tag]         android-cts-2.3_r10 -> android-cts-2.3_r10
 * [new tag]         android-cts-2.3_r11 -> android-cts-2.3_r11
 * [new tag]         android-cts-2.3_r12 -> android-cts-2.3_r12
 * [new tag]         android-cts-4.0.3_r1 -> android-cts-4.0.3_r1
 * [new tag]         android-cts-4.0.3_r2 -> android-cts-4.0.3_r2
 * [new tag]         android-cts-4.0_r1 -> android-cts-4.0_r1
 * [new tag]         android-cts-4.1_r1 -> android-cts-4.1_r1
 * [new tag]         android-cts-4.1_r2 -> android-cts-4.1_r2
 * [new tag]         android-cts-4.2_r1 -> android-cts-4.2_r1
 * [new tag]         android-cts-4.2_r2 -> android-cts-4.2_r2
 * [new tag]         android-cts-4.4_r1 -> android-cts-4.4_r1
 * [new tag]         android-cts-verifier-4.0.3_r1 -> android-cts-verifier-4.0.3_r1
 * [new tag]         android-cts-verifier-4.0_r1 -> android-cts-verifier-4.0_r1
 * [new tag]         android-sdk-4.0.3-tools_r1 -> android-sdk-4.0.3-tools_r1
 * [new tag]         android-sdk-4.0.3_r1 -> android-sdk-4.0.3_r1
 * [new tag]         android-sdk-4.4.2_r1 -> android-sdk-4.4.2_r1
 * [new tag]         android-sdk-adt_r16.0.1 -> android-sdk-adt_r16.0.1
 * [new tag]         android-sdk-adt_r20 -> android-sdk-adt_r20
 * [new tag]         android-sdk-support_r11 -> android-sdk-support_r11
Fetching projects: 100% (165/165), done.  
Checking out files: 100% (4679/4679), done.out files:  33% (1551/4679)   
Checking out files: 100% (4573/4573), done.out files:  40% (1845/4573)   
Checking out files: 100% (10008/10008), done.t files:  19% (1960/10008)   
Checking out files: 100% (11468/11468), done.t files:   8% (927/11468)   
Checking out files: 100% (7239/7239), done. out files:   1% (100/7239)   
Syncing work tree: 100% (165/165), done.

查看下载的版本是否与自己想要的相符合,进去

build\core\version_defaults.mk //搜索该文件中的 PLATFORM_VERSION值

编译方法参考官网:

点击打开链接


http://source.android.com/source/building-running.html

编译出错整理:

1.

frameworks/base/libs/utils/RefBase.cpp: 在成员函数‘void android::RefBase::weakref_type::trackMe(bool, bool)’中:
frameworks/base/libs/utils/RefBase.cpp:483:67: 错误: 将‘const android::RefBase::weakref_impl’作为‘void android::RefBase::weakref_impl::trackMe(bool, bool)’的‘this’实参时丢弃了类型限定 [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] 错误 1
make: *** 正在等待未完成的任务....
frameworks/base/libs/utils/ResourceTypes.cpp: 在成员函数‘void android::ResTable::print(bool) const’中:
frameworks/base/libs/utils/ResourceTypes.cpp:4369:84: 警告: 将一个整数转换为大小不同的指针 [-Wint-to-pointer-cast]
frameworks/base/libs/utils/ResourceTypes.cpp:4375:43: 警告: 将一个整数转换为大小不同的指针 [-Wint-to-pointer-cast]

解决:

打开Android.mk
$ gedit frameworks/base/libs/utils/Android.mk
将下面这一行
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
改为
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

2.

host C: parseStringTest <= external/srec/tools/parseStringTest/parseStringTest.c
<命令行>:0:0: 错误: “_FORTIFY_SOURCE”重定义 [-Werror]
<built-in>:0:0: 附注: 这是先前定义的位置
<命令行>:0:0: 警告: “_FORTIFY_SOURCE”重定义 [默认启用]
<built-in>:0:0: 附注: 这是先前定义的位置
host C++: post_trace <= sdk/emulator/qtools/post_trace.cpp
<命令行>:0:0: 警告: “_FORTIFY_SOURCE”重定义 [默认启用]
<built-in>:0:0: 附注: 这是先前定义的位置
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] 错误 1
make: *** 正在等待未完成的任务....

解决:

修改源码目录下/build/core/combo/HOST_linux-x86.mk文件:

将以下语句


HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0


修改为


HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0


编译大概一个半小时,完成源码编译:

target Strip: slesTest_seekTorture (out/target/product/generic/obj/EXECUTABLES/slesTest_seekTorture_intermediates/slesTest_seekTorture)
target Strip: slesTest_sendToPresetReverb (out/target/product/generic/obj/EXECUTABLES/slesTest_sendToPresetReverb_intermediates/slesTest_sendToPresetReverb)
target Strip: slesTest_slowDownUri (out/target/product/generic/obj/EXECUTABLES/slesTest_slowDownUri_intermediates/slesTest_slowDownUri)
target Strip: slesTest_srcsink (out/target/product/generic/obj/EXECUTABLES/slesTest_srcsink_intermediates/slesTest_srcsink)
target Strip: slesTest_urimime (out/target/product/generic/obj/EXECUTABLES/slesTest_urimime_intermediates/slesTest_urimime)
target Strip: slesTest_virtualizer (out/target/product/generic/obj/EXECUTABLES/slesTest_virtualizer_intermediates/slesTest_virtualizer)
Install: out/target/product/generic/system/lib/libmediaplayerservice.so
target Executable: mediaserver (out/target/product/generic/obj/EXECUTABLES/mediaserver_intermediates/LINKED/mediaserver)
target SharedLib: libsystem_server (out/target/product/generic/obj/SHARED_LIBRARIES/libsystem_server_intermediates/LINKED/libsystem_server.so)
Install: out/target/product/generic/system/bin/testid3
target Non-prelinked: libwebcore (out/target/product/generic/symbols/system/lib/libwebcore.so)
target Non-prelinked: mediaserver (out/target/product/generic/symbols/system/bin/mediaserver)
target Non-prelinked: libsystem_server (out/target/product/generic/symbols/system/lib/libsystem_server.so)
target Strip: mediaserver (out/target/product/generic/obj/EXECUTABLES/mediaserver_intermediates/mediaserver)
target Strip: libsystem_server (out/target/product/generic/obj/lib/libsystem_server.so)
target Strip: libwebcore (out/target/product/generic/obj/lib/libwebcore.so)
Install: out/target/product/generic/system/bin/mediaserver
Install: out/target/product/generic/system/lib/libsystem_server.so
target Executable: system_server (out/target/product/generic/obj/EXECUTABLES/system_server_intermediates/LINKED/system_server)
target SharedLib: libandroid_servers (out/target/product/generic/obj/SHARED_LIBRARIES/libandroid_servers_intermediates/LINKED/libandroid_servers.so)
target Non-prelinked: system_server (out/target/product/generic/symbols/system/bin/system_server)
target Strip: system_server (out/target/product/generic/obj/EXECUTABLES/system_server_intermediates/system_server)
target Non-prelinked: libandroid_servers (out/target/product/generic/symbols/system/lib/libandroid_servers.so)
target Strip: libandroid_servers (out/target/product/generic/obj/lib/libandroid_servers.so)
Install: out/target/product/generic/system/lib/libwebcore.so
Install: out/target/product/generic/system/bin/system_server
target Executable: webcore_test (out/target/product/generic/obj/EXECUTABLES/webcore_test_intermediates/LINKED/webcore_test)
target Non-prelinked: webcore_test (out/target/product/generic/symbols/system/bin/webcore_test)
target Strip: webcore_test (out/target/product/generic/obj/EXECUTABLES/webcore_test_intermediates/webcore_test)
Install: out/target/product/generic/system/lib/libandroid_servers.so
Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp
Combining NOTICE files: out/target/product/generic/obj/NOTICE.html
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Installed file list: out/target/product/generic/installed-files.txt

测试编译是否成功:

$ source build/envsetup.sh
$ lunch full-eng
$ emulator

或者指定运行刚刚编译出来的img:

$ cd out/target/product/generic
$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img

如果没错的话,android模拟器就自动运行起来了。

-------------------------------------------------------------------------------------------------------------

如果要使用自己编译出来的sdk做开发,可以执行下面的命令:

$ make sdk

编译大概半个小时完成。

Docs droiddoc: out/target/common/docs/dx
DroidDoc took 3 sec. to write docs to out/target/common/docs/dx
dalvik/dx/src/com/android/dx/dex/code/StdCatchBuilder.java:266: warning 1: Unresolved link/see tag "CatchTable#Entry" in com.android.dx.dex.code.StdCatchBuilder
dalvik/dx/src/com/android/dx/dex/file/AnnotationItem.java:49: warning 1: Unresolved link/see tag "#TypeIdSorter" in com.android.dx.dex.file.AnnotationItem
dalvik/dx/src/com/android/dx/rop/code/Exceptions.java:67: warning 3: Unknown tag: @code[java.lang.Error,
dalvik/dx/src/com/android/dx/rop/code/Exceptions.java:74: warning 3: Unknown tag: @code[java.lang.Error,
dalvik/dx/src/com/android/dx/rop/code/RegisterSpec.java:213: warning 1: Unresolved link/see tag "#ForComparison.equals" in com.android.dx.rop.code.RegisterSpec
dalvik/dx/src/com/android/dx/rop/code/RegisterSpec.java:265: warning 1: Unresolved link/see tag "#ForComparison.hashCode" in com.android.dx.rop.code.RegisterSpec
dalvik/dx/src/com/android/dx/ssa/Dominators.java:166: warning 4: @param tag with name that doesn't match the parameter list: 'meth'
dalvik/dx/src/com/android/dx/ssa/back/SsaToRop.java:81: warning 4: @param tag with name that doesn't match the parameter list: 'ssaMeth'
dalvik/dx/src/com/android/dx/util/ByteArray.java:251: warning 1: Unresolved link/see tag "#GetCursor" in com.android.dx.util.ByteArray
dalvik/dx/src/com/android/dx/util/ByteArray.java:264: warning 1: Unresolved link/see tag "#GetCursor" in com.android.dx.util.ByteArray
dalvik/dx/src/com/android/dx/util/ByteArray.java:347: warning 1: Unresolved link/see tag "#MyInputStream" in com.android.dx.util.ByteArray.MyDataInputStream
dalvik/dx/src/com/android/dx/util/ByteArray.java:352: warning 1: Unresolved link/see tag "#MyInputStream" in com.android.dx.util.ByteArray.MyDataInputStream
Docs droiddoc: out/target/common/docs/dexdeps
DroidDoc took 0 sec. to write docs to out/target/common/docs/dexdeps
Package SDK Stubs: out/target/common/obj/PACKAGING/android_jar_intermediates/android.jar
Package SDK: out/host/linux-x86/sdk/android-sdk_eng.username_linux-x86.zip

然后配置eclipse sdk 路径指向编译出来的sdk,

即out/host/linux-x86/sdk/android-sdk_eng.username_linux-x86

还要加android.jar加去工程才可使用,

out/target/common/obj/PACKAGING/android_jar_intermediates/android.jar