發文作者:wekon | 五月 12, 2009

Android Notes

android

I was devastated by Android these days
let me organize some noticeable points here
(ubuntu 8.10 is used)

1. download Android source code (cupcake)

create home:
:mkdir AndroidHome

install Git:
:sudo apt-get install git-core

install Repo:
:curl http://android.git.kernel.org/repo > ~/AndroidHome/bin/repo
:chmod a+x ~/AndroidHome/bin/repo

install Python:
:sudo apt-get install python

install JDK 1.6:
:cd ~/AndroidHome/downloads
:chmode a+x jdk-6u11-linux-i586.bin
:.jdk-6u11-linux-i586.bin
:cp -R jdk1.6.0_11/ /usr/local/jdk1.6.0_11/
add followings to ~/.bashrc:
:export PATH=/usr/local/jdk1.6.0_11/bin:$PATH
:export JAVA_HOME=/usr/local/jdk1.6.0_11
:export ANDROID_JAVA_HOME=$JAVA_HOME

start to download:

:cd ~/AndroidHome/
:repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
(or :repo init -u git://android.git.kernel.org/platform/manifest.git -b release-1.0 for older version)
:repo sync

2. make Android source code

:make

The following error occurs

external/qemu/sockets.c: In function ?sock_address_init_resolve?:
external/qemu/sockets.c:637: error: ?EAI_NODATA? undeclared (first use
in this function)
external/qemu/sockets.c:637: error: (Each undeclared identifier is
reported only once
external/qemu/sockets.c:637: error: for each function it appears in.)

solution:

add “#if …" and “#endif" before and after case EAI_NODATA in sockets.c

#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME
case EAI_NODATA:
#endif
case EAI_NONAME:
err = ENOENT;
break;

after that, another ploblem occurs
the process is killed while making dex file
the reason is that the memory is not enough
it seams that at least 1.5G RAM and 10G HD space is required
so I setup the swap space to 2G

:dd if=/dev/zero of=/swapfile bs=1024 count=2000000
:mkswap /swapfile
:swapon /swapfile
:/swapfile swap swap defaults 0 0

finally, the make finished, which took about 4~6 hours

after the build success, the apk files will be in out/target/product/generic/system/app

3. make SDK

** important: JDK 1.5, not 1.6, must be used **
otherwise, the following error will occur:
javadoc: error – In doclet class DroidDoc,  method start has thrown an
exception java.lang.reflect.InvocationTargetException
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for
sun.util.resources.OpenListResourceBundle not found
1 error
make: *** [out/target/common/docs/dx-timestamp] Error 45

:make sdk

4. make ADT

If you use Android 1.5 SDK, you have to update the ADT to 0.9.0
Otherwise, there will errors occur
Normally, the update of ADK can be done easily through the “Software Updates" in eclipse
However, the ADT server cannot be connected to these days
Even the older version (0.8.0) is also not available
So, you have to make it by yourself

:development/tools/eclipse/scripts/build_server.sh ~/adt/

And then, how to install it into the eclipse?
choose “help" -> “Software Updates" -> “Add Site" -> “Local"
and then select the folder of ADT

5. create AVD (Android Virtual Device)

you have to create AVD for, otherwise, eclipse may display the following error:
Failed to find an AVD compatible with target ‘Android 1.5’. Launch aborted.

D:\Android SDK\android-sdk-windows-1.5_r1\tools>android list
D:\Android SDK\android-sdk-windows-1.5_r1\tools>android create avd –name aid15r1 –target 2

6. build module to APK

:cd ~/AndroidHome/src
:. build/envsetup.sh
:mmm packages/apps/Contacts/

p.s. however, if there is any import from another module in the current module, I still cannot build it successfully …

7. build your module in elipse

first of all, place your srource codes in packages/apps/YourModuleName/src

:cd /AndroidHome
:cp development/ide/eclipse/.classpath .
:chmod u+w .classpath
Now edit that copy of .classpath, if necessary.

in eclipse:
File > New > Java Project
enter your project name
Select “Create project from existing source", enter the path to your Android root directory, and click Finish.
if it doesn’t start to build, uncheck and re-check Project > Build Automatically to force a rebuild

Project > Properties
Select “Java Build Path" from the left-hand menu.
Choose the “Source" tab.
Click “Add Folder…".
Add your module’s “src" directory.
Click OK.

After the build success, the class file will be in out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes

p.s. I still don’t know how to build the apk file of my module in eclipse …

8. deal with devices/emulators

enter the device:
>adb shell

list directories/files:
#ls

system applications are mainly in /system/app/

install apk:
>adb install YourAPK.apk
installed apk will be placed in /data/local/tmp

push data into device:
>adb push test.txt /tmp/test.txt
** you cannot push apk files into /system/app/ on real device**
if you push files into /system/app/ on emulator, the following error may occur:
failed to copy ‘xxx.apk’ to ‘system/app/xxx.apk’: Read-only file system
solution:
>adb remount

get data from device:
>adb pull /addroid/lib/libwebcore.so .

9. build the system image

:make snod

[References]
http://source.android.com/download
http://wenda.tianya.cn/wenda/thread?tid=267c01a129014d01&clk=wttpcts
http://www.rin.org.cn/2009/05/04/android_make/
http://groups.google.com/group/android-platform/browse_thread/thread/153e2155e33c6555
http://www.dubblogs.cc/roller/Android/entry/test
http://mmmyddd.freeshell.net/wiki/android/build.html
http://www.iim.nctu.edu.tw/~richardlin/blog/?p=7
http://bbase.mobi/mediawiki/intro/installing.html
http://547600.javaeye.com/blog/368166
http://blog.chinaunix.net/u2/85805/showart_1897152.html
http://www.cppblog.com/kaisne/archive/2009/04/29/81493.html
http://stackoverflow.com/questions/560411/application-source-code-for-contactsandroid
http://source.android.com/using-eclipse
http://stenlyho.blogspot.com/2008/11/androidadb.html
http://www.mailinglistarchive.com/android-developers@googlegroups.com/msg08828.html
http://blog.chinaunix.net/u2/86601/showart.php?id=1885062
http://www.javaworld.com.tw/jute/post/view?bid=26&id=256165&tpg=1&ppg=1&sty=1#257795
http://blog.csdn.net/HKjinzhao/archive/2009/03/18/4002326.aspx
http://www.androidchina.org.cn/45.html
http://planet.nccucs.org/2008/09/04/678/
http://lotushy.blogspot.com/2008/10/android-sdk-developing-android.html
http://www.rankolife.cn/blog-280.html
http://forum.xda-developers.com/showthread.php?t=507244&page=42
http://blog.ring.idv.tw/comment.ser?i=252
http://nsutt.wordpress.com/2009/02/
http://kuikui.javaeye.com/category/26593?show_full=true
http://groups.google.com/group/android-framework/browse_thread/thread/7d43ce3cdbac35a8
http://groups.google.com/group/android-platform/browse_thread/thread/de555a2f3029ab1a


Responses

  1. 請問一下 android 程式中 “/"根目錄位於哪裡?真的找了很久,希望能解決!謝謝

  2. 不太確定你想問的問題是什麼
    安裝時如果是安裝在 linux 上, 根目錄就是你的 linux 的根目錄; 執行 Android 程式時, 根目錄就是 Android 底層的 linux 的根目錄
    至於程式裡面哪裡有用到根目錄,我就沒什麼印象了

  3. From the programming and service side, youth development frameworks are also moving away from deficit models, valuing instead young people for their potential, and designing interventions to build a set of core competencies needed to participate successfully as adolescents and adults. ,

  4. We can surely train people to do more to inhibit their disdainful and offended responses in face-to-face interactions with those perceived as physically unattractive. ,

  5. The ability to bounce back from hard times or to deal with problems when they come is a big part of good mental health. ,

  6. 請問有辦法將某個apk file放在Adroid source code裡面,等我build完之後,將image燒到手機裡面,而這個apk也可以出現,不要使用到adb tool

    • 我沒有試過這種方式
      所以可能沒辦法直接回答你
      建議可以先嘗試直接學 install 之後的目錄結構來放置 apk 檔
      如果不行,可能是需要跟 Android 進行註冊
      可能就要參考 install 過程中到底做了哪些事情了

      • ok~~還是感謝您的回應,希望還可以繼續跟您討論….^_^

  7. hi wekon,
    請問你有試過下載 Android 2.0 (Eclair)過嗎?
    我發現repo sync一直跑不到完,到最後總是會有些怪錯誤出來,而且在我建的myAndroid 目錄下,也找不到Makefile可以make,不知道你有沒有什麼好建議呢?

    • 不好意思, 沒有用過耶

      • 謝謝你的答覆 ~~
        因為最近我也是 devastated by Android these days
        光repo sync 就常出現一堆怪問題 害我重裝很多次
        好不容易拜讀你的文章 在repo init 後面多加個 -b eclair
        好像稍微正常一點跑到完 但是現在又卡在 Java version 上面
        可是網路上明明有人說 可以用 Fedora openjdk 1.6去編譯的

  8. to kalo:
    我沒有碰過這個問題
    也許你可以換別的 version of java 試試看
    good luck


發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

分類

%d 位部落客按了讚: