Showing posts with label android. Show all posts

fix Android building error on ubuntu 11.10

系統升級 ubuntu 11.10 過程相當順利,瀏覽器資料也多虧 sync 的功能一下子就回復,雲端的時代來了(笑)。
升級後編譯 Android 出現錯誤,仔細比對後因為 gcc/glibc 的版本不同所造成,許多問題 google 真的可以找到解法省下不少時間,不過也要慢慢累積經驗,可以看到問題直覺反應如何解決!
先把遇到的問題跟解法一點一滴記錄下來吧。
  • Xubuntu 11.10 Oneiric Ocelot AMD64
  • gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) (system default)
  • Android 2.2.1 (MDK3D BSP)

  • compile the Android 2.3 with your installed GCC 4.6, you will receive the following error message:

    host Executable: acp (out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp)
    host SharedLib: libneo_cs (out/host/linux-x86/obj/lib/libneo_cs.so)
    host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’: frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive] make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1 make: *** Waiting for unfinished jobs....

    To fix that, open a terminal and run (assuming you are in the folder android):
    diff  frameworks/base/libs/utils/Android.mk
    
    - LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
    + LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive
    

  • to solve undefined reference to `pthread_create'
    host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
    out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':
    android/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'
    out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
    android/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'
    android/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'
    collect2: ld returned 1 exit status
    make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] error 1
    
    diff frameworks/base/tools/appt/Android.mk
    
     ifeq ($(HOST_OS),linux) 
    -LOCAL_LDLIBS += -lrt 
    +LOCAL_LDLIBS += -lrt -lpthread 
     endif 
    
  • another undefined reference to `pthread_create'
    out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_get':
    android/bin/system/core/libcutils/threads.c:27: undefined reference to `pthread_getspecific'
    out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a(threads.o): In function `thread_store_set':
    android/bin/system/core/libcutils/threads.c:36: undefined reference to `pthread_key_create'
    android/bin/system/core/libcutils/threads.c:44: undefined reference to `pthread_setspecific'
    collect2: ld returned 1 exit status
    make: *** [out/host/linux-x86/obj/EXECUTABLES/localize_intermediates/localize] error 1
    
    diff frameworks/base/tools/localize/Android.mk
    
     ifeq ($(HOST_OS),linux) 
    -LOCAL_LDLIBS += -lrt 
    +LOCAL_LDLIBS += -lrt -lpthread 
     endif 
    

後來看到一個大陸的網頁,寫得相當完整。大陸急起直追的力道真的很強勁,該百尺竿頭!

Android develop resources for ubuntu

  • Fastboot is protocol used to update the flash filesystem in Android devices from a host over USB. It allows flashing of unsigned partition images. It is disabled in the production Android-Dev devices since USB support is disabled in the bootloader. This can be changed if you get root on the device.
    Just following the step introducted in [HOW-TO]Set up Android SDK/ADB/Fastboot on Ubuntu Linux. This HOW-TO works well under Ubuntu 10.04 TLS.
    .
  • Bash completion script for the android, adb, and emulator command-line tools from the Google Android SDK
    https://github.com/mbrubeck/android-completion
    Copy the "android" file from this directory into the /etc/bash_completion.d folder

Android.mk 筆記

---
  1. 不建議將 Linux kernel driver 直接放入 Android source tree.
  2. Android building system 與 Linux kernel source 兩者使用的 Building system 行為與 config/ c flag 並不相同.
  3. 所以多習慣預先編譯 .ko 檔, 然後在 products.mk 中寫明 PRODUCT_COPY_FILES

Android building system 簡單介紹

重點在於 LOCAL_MODULES 跟 LOCAL_SHARE_MODULES 這兩個參數去建構出所有需使用到的 modules
所以的 runtime library 的 LOCAL_NAME 一定要被上層 MODULES 所使用


(Jollen 所提供的 mokoid/hardware/modules/led 範例, 較簡單易懂)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

# our own branch needs these headers
LOCAL_C_INCLUDES += \
vendor/mokoid/hardware/modules/include/
    編譯此 project 時所使用的 include 檔位置
    Android build system 會指名自己的 includes files path, 而各個 project 可自行指名所使用的 include path
    #include "a.h" 
    編譯系統會到 LOCAL_C_INCLUDES 找這個 header file.

LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_SHARED_LIBRARIES := liblog
    編譯本 modules 所需使用的其他 modules
    Android build system 會以所有 Android.mk 中的 LOCAL_MODULE 的名字命名.
    並依該 modules 所使用的 SHARED_LIBRARIES 去建立 building tree
    以這個例子來說, 要編 led.goldfish 需先編譯 liblog 這個 modules

LOCAL_SRC_FILES := led.c
    本 modules 的 c code

LOCAL_MODULE := led.goldfish
#LOCAL_MODULE := led.dma6410xp
    上述的此 modules name

include $(BUILD_SHARED_LIBRARY)



(0xdroid/hardware/alsa_sound/Android.mk, 多了一些環境變數的檢查, 比較完整也較複雜, 基本行為一樣)
# hardware/libaudio-alsa/Android.mk
# Copyright 2008 Wind River Systems
#

ifeq ($(strip $(BOARD_USES_ALSA_AUDIO)),true)
 LOCAL_PATH := $(call my-dir)

 include $(CLEAR_VARS)

 LOCAL_ARM_MODE := arm
 LOCAL_CFLAGS := -D_POSIX_SOURCE

 LOCAL_WHOLE_STATIC_LIBRARIES := libasound

 ifneq ($(ALSA_DEFAULT_SAMPLE_RATE),)
   LOCAL_CFLAGS += -DALSA_DEFAULT_SAMPLE_RATE=$(ALSA_DEFAULT_SAMPLE_RATE)
 endif
 ifeq ($(strip $(BOARD_HAVE_FM_ROUTING)),true)
   LOCAL_CFLAGS += -DFM_ROUTE_SUPPORT
 endif

 LOCAL_C_INCLUDES += external/alsa-lib/include

 LOCAL_SRC_FILES := AudioHardwareALSA.cpp

 LOCAL_MODULE := libaudio

 LOCAL_STATIC_LIBRARIES += libaudiointerface

 LOCAL_SHARED_LIBRARIES := \
   libcutils \
   libutils \
   libmedia \
   libhardware \
   libhardware_legacy \
   libdl \
   libc

 include $(BUILD_SHARED_LIBRARY)
 include $(CLEAR_VARS)
 LOCAL_PRELINK_MODULE := false
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_CFLAGS := -D_POSIX_SOURCE -Wno-multichar
    給 gcc 用的 flag, 這部份詳細下法必須參考 gcc manual
    這跟 pkg-config 沒有關係

 LOCAL_C_INCLUDES += external/alsa-lib/include
 LOCAL_SRC_FILES:= acoustics_default.cpp
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_MODULE:= acoustics.default
 include $(BUILD_SHARED_LIBRARY)
endif

Android 3.0 GPUI (hardware accelerated UI)

Android 並沒有 Windowing 的架構,Application 建立 Surface 後進行繪圖與顯示。Andorid 中繪圖有幾種方式:Canvas - 2D drawing context, Skia – 2D drawing API, OpenGL – 3D rendering API 以及 Android 2.2 之後開始支援的 OpenGL|ES 2.0 規格,開發者可使用 RenderScript (Language + API) 繪製3D圖型。

為確保 Application 能正常在各個 Android 平台上執行,Android 實作了軟體 OpenGL|ES API - libAGL.so。若裝置上並沒有 GPU 的話,則以軟體來處理 3D graphic;而若 Android 裝置有 GPU,則由 GPU 所提供的 libHGL_cyclone.so 把 3D 圖形轉交給 GPU 去運算,效能會好許多。

Application 可以使用 Canvas 透過 skia library 繪製、直接使用 OpenGL|ES 1.x fixed API 來繪製 3D graphic,或使用 OpenGL|ES 2.0 的 RenderScript,開發者得選用相對應的 Surface 去繪圖。

Android 3.0 重寫了常用的 2D UI compoment 繪製方式,特點是借用 GPU 對圖形處理能力來加快效能,稱為 UI on the GPU,簡稱 GPUI。GPUI 基本運作概念是將每個 2D UI component 轉換成兩個三角形的物件去貼圖,這部份的觀念跟先前 Android 處理 LayerBuffer 的作法一樣。而藉由GPU的處理,在shading、alpha blanding...等運算上,速度會比原本使用 Cavans + skia + pixelfligner 快許多。

對開發者而言,Android GPUI 提供多種不同層級 hardware acceleration 設定,可分別針對 Applicaion、Activity、Window、View 去設定是否使用 hardware acceleration。若程式中僅使用標準 drawable 元件例如list、button、path...等標準 2D UI component,程式開發員可以打開 Hardware acceleration 功能,以使用GPU 繪製。開發者也可以利用 View.isHardwareAccelerated() / Canvas.isHardwareAccelerated() 來得知所運行的平台是否支援 GPU 硬體加速,用以選擇所使用的 UI component,達最佳顯示效果。

在 Android 發展中,愈來愈多 application 使用 3D graphic 去做 UI 特效處理,而 Android 本身亦利用 GPU 的特性對於 2D UI component 做最佳化,GPU 在 Android 上扮演愈來愈重要的角色。

Android 3.0 Platform Highlights
http://developer.android.com/sdk/android-3.0-highlights.html
Android 3.0 Hardware Acceleration
http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html
Make android use the GPU (if available) for UI and browsing.
http://code.google.com/p/android/issues/detail?id=6914
The Care and Feeding of the Android GPU
http://www.satine.org/archives/2011/01/01/the-care-and-feeding-of-the-android-gpu/
Make Android use the GPU (if available) for UI and browsing
http://www.androidannoyances.com/post/10
Android 3.0 (Honeycomb): Introducing Hardware Accelerated 2D Graphics and Tips to Use it Properly
http://goo.gl/nWe40

Surface
Graphics in Android - an Introduction
Android Display System --- Surface Flinger
Android display架构分析

OpenGL ES | Hardware acceleration
Android OpenGL ES 分析与实践

followed android repo manifest.git list

Official Android Source
repo init -u git://android.git.kernel.org/platform/manifest.git

0xdroid by 0xlab
Project page / SCM: http://gitorious.org/0xdroid
Bug report: http://code.google.com/p/0xdroid/issues/list
Mailing-list (general): http://groups.google.com/group/0xlab-discuss
Mailing-list (development): http://groups.google.com/group/0xlab-devel
0xlab YouTube channel: http://www.youtube.com/channel/0xlab
repo init -u git://gitorious.org/0xdroid/manifest.git -b beagle-cupcake

beagleboard by embinux
stable cupcake build
repo init -u git://labs.embinux.org/repo/android/platform/beaglemanifest.git/
donut build
repo init -u git://labs.embinux.org/omap3donut/repo/android/platform/omap3donutmanifest.git/

CyanogenMod
repo init -u git://github.com/abstrakraft/android-manifest.git

MIPS Android
repo init -u git://public.mipsandroid.com/mips/platform/manifest.git -b mips-cupcake

Android-x86 - Porting Android to x86 Platform
repo init -u git://git.android-x86.org/platform/manifest.git

NMI VK's team modified (III internal access only)
arm-nmi
repo init -u ssh://140.92.60.250//opt/repos/staffs/kywk/android/m.git -b nmi-arm-v7 -m nmi-arm-v7.xml
x86-nmi
repo init -u ssh://140.92.60.250//opt/repos/staffs/kywk/android/m.git -b nmi-x86-atom -m nmi-x86-atom.xml


android on beagleboard project list:
0xdroid, Mentor Graphics, embinux