2011年12月29日 星期四

如何編譯Android Ice Cream Sandwich

此篇文章主要記錄在Macbook Pro(mbp), OSX Lion上編譯ICS的Android source code的步驟, 不過應該Linux系統上也相同, 而且簡單許多, OSX上需要多做一些修改.

基本步驟
  1. 按照官網下載source code並設定環境
  2. 設定ccache, 原因是能夠加速c/c++的compiler速度(官網)
    $ export USE_CCACHE=1
    $ export CCACHE_DIR=/<path_of_your_choice>/.ccache
    $ prebuilt/linux-x86/ccache/ccache -M 20G
  3. 下載廠商提供的binary檔案, 我的手機是Nexus S, 所以Google提供
  4. 準備編譯
    1. 先將環境清乾淨
      make clobber
      
    2. 設定環境變數
      source build/envsetup.sh
    3. 設定編譯選項
      lunch
  5. 編譯
    make -j 4
    



蠢事集合
  1. code沒有換到 ics 4.0.3
    • 因為一開始ics source code release時官網建議
      repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.1_r1
    • 解法
      1. 取得可以用可以用的branch
        git --git-dir .repo/manifests/.git/ branch -a
      2. 切換到最新的branch, 此時最新的是android-4.0.3_r1
        repo forall -c git checkout -b android-4.0.3_r1
        
  2. lunch看不到crespo(Nexus S的代號, 官網可以查到)
    • 因為顯示的option是由build/envsetup.sh產生, 而我在把source code更新成android-sdk-4.0.3_r1後, 沒有重新source build/envsetup.sh, 所以沒有新增
    • 其實也可以用 add_lunch_combo full_crespo-userdebug 加入option
  3. OSX Lion編譯問題 - strnlen
    • OSX Lion 在/usr/include/string.h 也定義了strnlen, 會發生重復定義, Reference
    • 將android定義的拿掉
      diff -u external/elfutils/config-compat-darwin.h external/elfutils/config-compat-darwin.h_org
      --- external/elfutils/config-compat-darwin.h 2011-08-20 08:50:29.000000000 +0200
      +++ external/elfutils/config-compat-darwin.h_org 2011-08-20 08:49:27.000000000 +0200
      @@ -38,7 +38,6 @@
        return NULL;
       }
       
      -#if 0
       static inline size_t strnlen (const char *__string, size_t __maxlen)
       {
        int len = 0;
      @@ -46,7 +45,6 @@
         len++;
        return len;
       }
      -#endif
       
       static inline void *mempcpy (void * __dest, const void * __src, size_t __n)
       {
  4. OSX Lion編譯問題 - XCode4 跟 libSDL
    • 在拜讀過google大神後找到解法, 加入下列patch
    1. build project
      diff --git a/core/combo/HOST_darwin-x86.mk b/core/combo/HOST_darwin-x86.mk
      index 544a29e..407c74f 100644
      --- a/core/combo/HOST_darwin-x86.mk
      +++ b/core/combo/HOST_darwin-x86.mk
      @@ -53,7 +53,11 @@ HOST_JNILIB_SUFFIX := .jnilib
      
       HOST_GLOBAL_CFLAGS += \
              -include $(call select-android-config-h,darwin-x86)
      -HOST_RUN_RANLIB_AFTER_COPYING := true
      +ifneq ($(filter 10.7.%, $(build_mac_version)),)
      +       HOST_RUN_RANLIB_AFTER_COPYING := false
      +else
      +       HOST_RUN_RANLIB_AFTER_COPYING := true
      +endif
       HOST_GLOBAL_ARFLAGS := cqs
      
       HOST_CUSTOM_LD_COMMAND := true
    2. development project 修改1
      diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk b/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk
      index deb11b6..a73f6b8 100644
      --- a/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk
      +++ b/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk
      @@ -8,6 +8,15 @@ LOCAL_SDL_CONFIG ?= prebuilt/$(PREBUILT)/sdl/bin/sdl-config
       LOCAL_SDL_CFLAGS := $(shell $(LOCAL_SDL_CONFIG) --cflags)
       LOCAL_SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(LOCAL_SDL_CONFIG) --static-libs))
      
      +ifeq ($(HOST_OS),darwin)
      +  DARWIN_VERSION := $(strip $(shell sw_vers -productVersion))
      +  ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),)
      +    # Lion needs to be forced to link dylib to avoid problems
      +    # with the dynamic function lookups in SDL 1.2
      +    LOCAL_SDL_LDLIBS += /usr/lib/dylib1.o
      +  endif
      +endif
      +
       LOCAL_SRC_FILES:= \
               triangleCM.cpp
      
    3. development project 修改2
      diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk b/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk
      index ae0064f..efbe6bd 100644
      --- a/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk
      +++ b/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk
      @@ -17,6 +17,12 @@ LOCAL_LDLIBS += $(LOCAL_SDL_LDLIBS)
       LOCAL_STATIC_LIBRARIES += libSDL libSDLmain
      
       ifeq ($(HOST_OS),darwin)
      +DARWIN_VERSION := $(strip $(shell sw_vers -productVersion))
      +ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),)
      +  # Lion needs to be forced to link dylib to avoid problems
      +  # with the dynamic function lookups in SDL 1.2
      +  LOCAL_LDLIBS += /usr/lib/dylib1.o
      +endif
       $(call emugl-import,libMac_view)
       endif
    4. external/qemu project
      diff --git a/Makefile.android b/Makefile.android
      index e58f984..d638640 100644
      --- a/Makefile.android
      +++ b/Makefile.android
      @@ -74,8 +74,8 @@ ifeq ($(HOST_OS),darwin)
           ifneq ($(filter 10.1 10.2 10.3 10.1.% 10.2.% 10.3.% 10.4 10.4.%,$(DARWIN_VERSION)),)
               $(error Building the Android emulator requires OS X 10.5 or above)
           endif
      -    ifeq ($(filter 10.5 10.5.%,$(DARWIN_VERSION)),)
      -        # We are on Snow Leopard or above
      +    ifneq ($(filter 10.6 10.6.%,$(DARWIN_VERSION)),)
      +        # We are on Snow Leopard
               LEOPARD_SDK := /Developer/SDKs/MacOSX10.5.sdk
               ifeq ($(strip $(wildcard $(LEOPARD_SDK))),)
                   $(info  Please install the 10.5 SDK on this machine at $(LEOPARD_SDK))
      @@ -191,6 +191,11 @@ endif
      
       ifeq ($(HOST_OS),darwin)
         QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
      +  ifneq ($(filter 10.7 10.7.%,$(DARWIN_VERSION)),)
      +    # Lion needs to be forced to link dylib to avoid problems
      +    # with the dynamic function lookups in SDL 1.2
      +    QEMU_SYSTEM_LDLIBS += /usr/lib/dylib1.o
      +  endif
       endif
      
       include $(LOCAL_PATH)/Makefile.common
Reference

  1. Android官方網站
  2. 編譯環境相關
  3. Nexus手機Binary檔案下載位置
  4. OSX Lion strnlen patch
  5. OSX Lion XCode4 dependency patch
  6. 指令說明
  7. 其他教學文章

沒有留言:

張貼留言