1. 程式人生 > >android 2.3原始碼下載

android 2.3原始碼下載

系統: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值

編譯方法參考官網:

編譯出錯整理:

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

版本參考資料:http://www.cnblogs.com/flyme/archive/2011/10/14/2211143.html

出錯參考資料:http://blog.csdn.net/pku_android/article/details/6967882

http://www.cnblogs.com/dwayne/archive/2011/11/16/2251734.html