2012年5月15日 星期二

Android 4.0.3 ICS release for Beaglebone, Beagleboard-XM


前陣子在 TI 的網站發現 TI 公佈了 Cortex-A8 處理器的 Android 4.0.3 (ICS),共有兩個版本,一個是 TI_Android_ICS_4_0_3_DevKit_3_0_0,這是給 Beagleboard-XM 使用的,可以由下面這個網頁查看 DeveloperGuide:

另一個版本是 TI_Android_ICS_4_0_3_DevKit_3_0_1,則是提供給 Beaglebone 使用的:

手邊有這些開發板的朋友也可以試試。 ^^

在記憶體少於 2GB 的環境編譯 Android 4.0 (ICS)

雖然現在大多數人的電腦都裝了大於 2GB 的記憶體,甚至可能已經在電腦上安裝到 8GB、16GB 了。但,有時若使用 VMware 的產品或 VirtualBox 等軟體建立虛擬機器時,可能在虛擬機器裡多半會配置 1GB 或 2GB 的記憶體。

不過,這麼一來編譯 Android 4.0 (ICS) 時可能會遇上如下的錯誤:


target Dex: core
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
make: *** [out/target/common/obj/JAVA_LIBRARIES/core_intermediates/noproguard.classes-with-local.dex] Error 1 

這個容易處理,修改 build/core/definitions.mk 這個檔案是可以解決的,修改方式如下:

diff --git a/build/core/definitions.mk b/build/core/definitions.mk
index b678158..b83b299 100644
--- a/build/core/definitions.mk
+++ b/build/core/definitions.mk
@@ -1525,7 +1525,7 @@ define transform-classes.jar-to-dex
 @echo "target Dex: $(PRIVATE_MODULE)"
 @mkdir -p $(dir $@)
 $(hide) $(DX) \
-    $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \
+    $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1024M) \
     --dex --output=$@ \
     $(incremental_dex) \
     $(if $(NO_OPTIMIZE_DX), \ 

2012年5月10日 星期四

在 Ubuntu 12.04 安裝及設定 JDK / JRE 6

蚊子學長在 "在 Ubuntu 12.04 LTS 安裝 Android SDK&NDK 開發環境" 這篇文章裡有提到在 Ubuntu 12.04 安裝 JDK 的方法,在這裡我再補充一些。


取得 JDK 6 的安裝檔,這裡示範是採用 64 位元的  jdk-6u32-linux-x64.bin 這個檔案,並將執行後得到的 jdk1.6.0_32 這個目錄搬移到 /usr/lib/jvm 路徑下。

接著在 /usr/lib/jvm 路徑下建立 jdk6-update-alternatives-script.sh 這個檔案,內容如下:

#!/bin/bash
# "Register JDK7 for update-alternatives Script in Debian Way"
# Based on 1. codeslinger's "install_java7_alternatives" from https://gist.github.com/445930
#          2. oracle-java6-plugin.deb postint script (for plugin)
# Modified by Cheng-Wei Chien, 2011-07-30
# ------------------------------------------------------------------------------
# Note:  This script works on x86 Debian GNU/Linux.
#        If you use other arch or distro, you may have to modify some parameters.
#
# Usage: 1. Extract jdk7 tar.gz to, for example, /usr/lib/jvm/java-7-oracle-1.7.0,
#           create a symbolic link /usr/lib/jvm/java-7-oracle to it.
#        2. Download java-7-oracle.jinfo from https://gist.github.com/1114515,
#           move it to /usr/lib/jvm/.java-7-oracle.jinfo, do some modification if necessary.
#        3. Run this script with sudo
#        4. sudo update-java-alternatives -s java-7-oracle
#        5. Have fun with jdk7!
#
# Trouble Shooting: If something goes wrong,
#        1. Uncomment "remove" commands and comment "install" commands.
#        2. Run this script again to rollback.
#        3. Fix what causes the problem, maybe typo or something else.
#        4. Comment "remove" commands and uncomment "install" commands
#        5. Run this script to update

# Force the shell to exit immediately if something goes wrong
set -e

# Follow the Debian's priority rule for java5 = 53, java6 = 63 .. I guess
priority=63

# Your jdk7 home, in this case, it's /usr/lib/jvm/java-7-oracle-1.7.0
# But I create a symbolic link /usr/lib/jvm/java-7-oracle to meet Debian's way
basedir=/usr/lib/jvm/jdk1.6.0_32

# Your man1 dir, you don't need to change this
mandir=$basedir/man/man1

# Variables from /usr/lib/jvm/.java-6-oracle.jinfo except HtmlConverter (not in jdk7)
jdk_var='appletviewer apt extcheck idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc'
jre_var='ControlPanel java java_vm javaws jcontrol keytool pack200 rmid rmiregistry unpack200 orbd servertool tnameserv jexec'
browser_var="xulrunner-addons firefox iceape iceweasel mozilla midbrowser xulrunner"

# Java plugin path, you don't need to change this
plugin=$basedir/jre/lib/amd64/libnpjp2.so

# First, gzip man1 files to meet the 1.gz form
if [ -e $mandir ]; then
  for i in $mandir/*.1.gz; do
    gzip $i
  done
fi

# Register jdk variables
for i in $jdk_var; do
  unset slave || true
  if [ -e $mandir/$i.1.gz ]; then
    slave="--slave /usr/share/man/man1/$i.1.gz $i.1.gz $mandir/$i.1.gz"
  fi
  #update-alternatives --remove $i $basedir/bin/$i
  update-alternatives --install /usr/bin/$i $i $basedir/bin/$i $priority $slave
done

# Register jre variables
for i in $jre_var; do
  unset slave || true
  if [ -e $mandir/$i.1.gz ]; then
    slave="--slave /usr/share/man/man1/$i.1.gz $i.1.gz $mandir/$i.1.gz"
  fi
  if [ $i = jexec ]; then
    #update-alternatives --remove jexec $basedir/jre/lib/jexec
    update-alternatives --install /usr/bin/jexec jexec $basedir/jre/lib/jexec $priority
  elif [ $i = java ]; then
    update-alternatives --install /usr/bin/java java $basedir/jre/bin/java $priority $slave --slave /usr/bin/policytool policytool $basedir/jre/bin/policytool
  else
    #update-alternatives --remove $i $basedir/jre/bin/$i
    update-alternatives --install /usr/bin/$i $i $basedir/jre/bin/$i $priority $slave
  fi
done

# Register plugins
for i in $browser_var; do
  if [ $i = xulrunner-addons ]; then
    browser=xulrunner-1.9
  else
    browser=$i
  fi
  #update-alternatives --remove $browser-javaplugin.so $plugin
  update-alternatives --install /usr/lib/$i/plugins/libjavaplugin.so $browser-javaplugin.so $plugin $priority
done

接著再建立 .jdk1.6.0_32.jinfo 這個檔案,請注意這個檔案會是一個隱藏檔,內容如下:

name=jdk1.6.0_32
alias=java-6-oracle
priority=63
section=non-free

jre ControlPanel /usr/lib/jvm/jdk1.6.0_32/jre/bin/ControlPanel
jre java /usr/lib/jvm/jdk1.6.0_32/jre/bin/java
jre java_vm /usr/lib/jvm/jdk1.6.0_32/jre/bin/java_vm
jre javaws /usr/lib/jvm/jdk1.6.0_32/jre/bin/javaws
jre jcontrol /usr/lib/jvm/jdk1.6.0_32/jre/bin/jcontrol
jre keytool /usr/lib/jvm/jdk1.6.0_32/jre/bin/keytool
jre policytool /usr/lib/jvm/jdk1.6.0_32/jre/bin/policytool
jre pack200 /usr/lib/jvm/jdk1.6.0_32/jre/bin/pack200
jre rmid /usr/lib/jvm/jdk1.6.0_32/jre/bin/rmid
jre rmiregistry /usr/lib/jvm/jdk1.6.0_32/jre/bin/rmiregistry
jre unpack200 /usr/lib/jvm/jdk1.6.0_32/jre/bin/unpack200
jre orbd /usr/lib/jvm/jdk1.6.0_32/jre/bin/orbd
jre servertool /usr/lib/jvm/jdk1.6.0_32/jre/bin/servertool
jre tnameserv /usr/lib/jvm/jdk1.6.0_32/jre/bin/tnameserv
jre jexec /usr/lib/jvm/jdk1.6.0_32/jre/lib/jexec
jdk appletviewer /usr/lib/jvm/jdk1.6.0_32/bin/appletviewer
jdk apt /usr/lib/jvm/jdk1.6.0_32/bin/apt
jdk extcheck /usr/lib/jvm/jdk1.6.0_32/bin/extcheck
jdk idlj /usr/lib/jvm/jdk1.6.0_32/bin/idlj
jdk jar /usr/lib/jvm/jdk1.6.0_32/bin/jar
jdk jarsigner /usr/lib/jvm/jdk1.6.0_32/bin/jarsigner
jdk javac /usr/lib/jvm/jdk1.6.0_32/bin/javac
jdk javadoc /usr/lib/jvm/jdk1.6.0_32/bin/javadoc
jdk javah /usr/lib/jvm/jdk1.6.0_32/bin/javah
jdk javap /usr/lib/jvm/jdk1.6.0_32/bin/javap
jdk jconsole /usr/lib/jvm/jdk1.6.0_32/bin/jconsole
jdk jdb /usr/lib/jvm/jdk1.6.0_32/bin/jdb
jdk jhat /usr/lib/jvm/jdk1.6.0_32/bin/jhat
jdk jinfo /usr/lib/jvm/jdk1.6.0_32/bin/jinfo
jdk jmap /usr/lib/jvm/jdk1.6.0_32/bin/jmap
jdk jps /usr/lib/jvm/jdk1.6.0_32/bin/jps
jdk jrunscript /usr/lib/jvm/jdk1.6.0_32/bin/jrunscript
jdk jsadebugd /usr/lib/jvm/jdk1.6.0_32/bin/jsadebugd
jdk jstack /usr/lib/jvm/jdk1.6.0_32/bin/jstack
jdk jstat /usr/lib/jvm/jdk1.6.0_32/bin/jstat
jdk jstatd /usr/lib/jvm/jdk1.6.0_32/bin/jstatd
jdk native2ascii /usr/lib/jvm/jdk1.6.0_32/bin/native2ascii
jdk rmic /usr/lib/jvm/jdk1.6.0_32/bin/rmic
jdk schemagen /usr/lib/jvm/jdk1.6.0_32/bin/schemagen
jdk serialver /usr/lib/jvm/jdk1.6.0_32/bin/serialver
jdk wsgen /usr/lib/jvm/jdk1.6.0_32/bin/wsgen
jdk wsimport /usr/lib/jvm/jdk1.6.0_32/bin/wsimport
jdk xjc /usr/lib/jvm/jdk1.6.0_32/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so
plugin firefox-javaplugin.so /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so
plugin iceape-javaplugin.so /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so
plugin iceweasel-javaplugin.so /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so
plugin mozilla-javaplugin.so /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so
plugin midbrowser-javaplugin.so /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so
plugin xulrunner-javaplugin.so /usr/lib/jvm/jdk1.6.0_32/jre/lib/amd64/libnpjp2.so

接著執行以下幾個指令:

$ chmod a+x jdk6-update-alternatives-script.sh
$ sudo ./jdk6-update-alternatives-script.sh
$ sudo update-java-alternatives -s jdk1.6.0_32

這麼一來,就將 JDK / JRE 6 整個搞定了!

上述的方法及腳本,我是參考 http://epsilony.net/mywiki/Ubuntu/JDK7Installation 這篇文章而來的。其中,腳本裡有些註解的說明我並沒有去修改它。


2012年5月9日 星期三

在 openSUSE 建立編譯 Android 的環境


雖然對 OpenSUSE 不算熟悉,但在過去短暫的使用經驗裡,我還挺喜歡將 OpenSUSE 當成 Desktop 的一個選擇。加上前陣子因為建議幾個同學可以將 OpenSUSE 安裝起來試試,於是自己也利用 VMware 裝了 OpenSUSE 12.1。

正巧手邊有 Android 2.3.4 (Gingerbread) 的原始碼,那麼就想在 OpenSUSE 上試試能不能編譯 Android 2.3.4。

打定主意後,我仔細閱讀了 http://source.android.com/source/initializing.html 這頁的說明,然後開始試著在 OpenSUSE 上將需要的套件安裝起來,並且終於順利編譯了 Android 2.3.4 (Gingerbread) 的原始碼。

以下列出我在 OpenSUSE 上安裝的套件:
  • gcc
  • gcc-32bit
  • gcc-c++
  • make
  • vim-enhanced
  • ctags
  • cscope
  • kernel-devel
  • ncurses-devel
  • man-pages
  • man-pages-posix
  • git
  • mercurial
  • flex
  • bison
  • gperf
  • zlib-devel
  • readline-devel
  • libzip-devel
  • python-markdown
  • lzo-devel
  • binutils-dev
  • mesa-devel
  • doxygen
  • indent
  • valgrind
  • valgrind-devel
  • screen
  • intltool
  • ccache
  • schedtool
  • libxml2-devel
  • java-1_6_0-openjdk
  • java-1_6_0-openjdk-devel
  • schedtool
  • libesd-devel
  • build
  • libSDL-devel
  • perl-Switch
  • xorg-X11-devel-32bit
  • xorg-x11-libX11-devel-32bit

PS. 其實這是之前整理的東西,我想多數使用者應該都習慣在 Ubuntu 編譯 Android,這篇文章就給大家當個參考吧!另外,對於 Fedora 的使用者,也可以參考 http://fedoraproject.org/wiki/HOWTO_Setup_Android_Development 這篇文章的說明,不過我實在用不慣 Fedora,就沒去驗證和確認了。 XD

在 OpenSUSE 12.1 安裝 Sun JDK 6


之前做過小小的嘗試,其實若安裝 OpenJDK,仍然是可以編譯 Android 2.3 的。

但是,若編譯的 Android 原始碼裡包含了 CTS 的部份,就會出現一堆編譯失敗的訊息。於是,我終究試著在 OpenSUSE 12.1 裡自行安裝 Sun JDK 6。

結果是,在 OpenSUSE 12.1 的套件庫裡找不到 Sun JDK 6,爬文之後似乎自己下載是最簡單的了。後來參考了這篇文章,我下載了 Sun JDK 1.6.0_31 (64bit) 的 jdk-6u31-linux-x64.bin 這個檔案。將它解開之後,得到一個 jdk1.6.0_31 目錄,並將它搬移到 /usr/lib64/jvm 目錄下。

接著編輯一個 java-alt.sh 檔案,內容如下:

#!/bin/bash
####Set your variables here####
JAVADIR="jdk1.6.0_31"
SYSLIB="lib64"
PRIORITY="18000"
########

if [ $SYSLIB == "lib64" ] ; then
PLUGINDIR="amd64"
else
PLUGINDIR="i386"
fi

update-alternatives --auto java

update-alternatives --install /usr/bin/java java /usr/$SYSLIB/jvm/$JAVADIR/bin/java $PRIORITY \
--slave /usr/$SYSLIB/jvm/jre jre /usr/$SYSLIB/jvm/$JAVADIR \
--slave /usr/$SYSLIB/jvm-exports/jre jre_exports /usr/$SYSLIB/jvm/$JAVADIR \
--slave /usr/bin/keytool keytool /usr/$SYSLIB/jvm/$JAVADIR/bin/keytool \
--slave /usr/bin/orbd orbd /usr/$SYSLIB/jvm/$JAVADIR/bin/orbd \
--slave /usr/bin/policytool policytool /usr/$SYSLIB/jvm/$JAVADIR/bin/policytool \
--slave /usr/bin/rmid rmid /usr/$SYSLIB/jvm/$JAVADIR/bin/rmid \
--slave /usr/bin/rmiregistry rmiregistry /usr/$SYSLIB/jvm/$JAVADIR/bin/rmiregistry \
--slave /usr/bin/servertool servertool /usr/$SYSLIB/jvm/$JAVADIR/bin/servertool \
--slave /usr/bin/tnameserv tnameserv /usr/$SYSLIB/jvm/$JAVADIR/bin/tnameserv \
--slave /usr/share/man/man1/java.1.gz java.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/java.1 \
--slave /usr/share/man/man1/keytool.1.gz keytool.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/keytool.1 \
--slave /usr/share/man/man1/orbd.1.gz orbd.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/orbd.1 \
--slave /usr/share/man/man1/policytool.1.gz policytool.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/policytool.1 \
--slave /usr/share/man/man1/rmid.1.gz rmid.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/rmid.1 \
--slave /usr/share/man/man1/rmiregistry.1.gz rmiregistry.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/rmiregistry.1 \
--slave /usr/share/man/man1/servertool.1.gz servertool.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/servertool.1 \
--slave /usr/share/man/man1/tnameserv.1.gz tnameserv.1.gz /usr/$SYSLIB/jvm/$JAVADIR/man/man1/tnameserv.1

update-alternatives --auto javaplugin

update-alternatives --install /usr/$SYSLIB/browser-plugins/javaplugin.so \
javaplugin /usr/$SYSLIB/jvm/$JAVADIR/jre/lib/$PLUGINDIR/libnpjp2.so $PRIORITY \
--slave /usr/bin/javaws javaws /usr/$SYSLIB/jvm/$JAVADIR/bin/javaws

update-alternatives --auto jdk_1.6.0

update-alternatives --install /usr/$SYSLIB/jvm/jdk-1.6.0 jdk_1.6.0 /usr/$SYSLIB/jvm/$JAVADIR $PRIORITY 

然後,以管理者身份執行該腳本就可以將系統的 Java JDK 安裝成 Sun JDK 6 了。

2012年5月4日 星期五

Ubuntu 12.04 64Bit 版本編譯 Android ICS原始碼錯誤解決方法

升級Ubuntu 12.04 64位元版本後,在 編譯 Android 4.0.4 (ICS)  Source Code 時會報錯:
....(略).....
/usr/bin/ld: cannot find -lGL
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/lib/lib64EGL_translator.so] Errore 1
make: *** waiting for unfinished jobs

2012年5月2日 星期三

在 Ubuntu 12.04 LTS 安裝 Android SDK&NDK 開發環境


Ubuntu「友幫拓」每年在4月及10月時會固定發布新版本,上月底 Ubuntu 發布了代號 Precise Pangolin(精確的穿山甲)的 12.04 LTS版本,這個版本官方網站將維護到 2017 年。
因此,近期將自己的 Ubuntu 開發環境也升級到 12.04,也將過程紀錄下來分享。