2008年8月24日 星期日

Android - 在 Android 模擬器中使用 SD 卡的 Image File


Android - 在 Android 模擬器中使用 SD 卡的 Image File

2008/08/24 13:54
Android - 在 Android 模擬器中使用 SD 卡的 Image File
建立 SD Card Image File(以下是指令)
cd .android
mksdcard -l sdcard 2048M demo-sdcard.img 
  <- 建立 2GB的 SD Card Image File , 模擬 2GB的 SD Card

注意: 在UBuntu 中 , Android的預設設定目錄是在你的home目錄下的 .android 目錄
(/home/demo/.android  它是隱藏目錄)


在UBuntu 中複製檔案或是存取 SD Card Image 中的檔案(以下是指令)
mkdir android_sdcard
sudo mount -o loop demo-sdcard.img android_sdcard

然後你就可以透過 android_sdcard 這個mount point 去存取檔案
例如複製 圖片 jpg 到 sd card 的 Image File中(以下是指令)
copy *.jpg ./android_sdcard/

如果不用了 , 記得下(以下是指令)
sudo  umount android_sdcard

在模擬器中中使用 SD Card Image(以下是指令)
emulator -sdcard  /home/demo/.android/demo-sdcard.img

在Eclipse 的整合環境中
當你去 Run Android Application 時的(Run As)啟動設定中的
Target 頁面的 Additional Emulator Command Line Options
輸入  -sdcard  /home/demo/.android/demo-sdcard.img

就可以讓模擬器去使用剛剛我們建立並放入檔案的 SD Card Image File

嗯 , mtools 我一直都跟它不熟 , 到現在我還是搞不定它 ,
我只好去整理出我覺得自己比較能夠簡單使用的方式

Android HelloAndroid 出現錯誤 - invalid constant pool index 0000

Google Android SDK - HelloAndroid 出現錯誤 - invalid constant pool index 0000


Android SDK - Beta1

Platform : UBuntu 8.0.4

IDE : Eclipse 3.4 (eclipse-jee-ganymede-linux-gtk)

JDK: 6.x

在安裝跟設定完 ADT  Plug-in之後 ,

根據說明文件在  Eclipse 下產生 HelloAndroid 並執行 ,
 結果出現錯誤訊息
[2008-08-21 22:15:45 - HelloAndroid] invalid constant pool index 0000
...while parsing LocalVariableTable attribute at offset 00000193
...while parsing attributes[1]
...while parsing Code attribute at offset 00000170
...while parsing attributes[0]
...while parsing methods[0]
...while parsing com/android/helloandroid/HelloAndroid.class
...while processing com/android/helloandroid/HelloAndroid.class
[2008-08-21 22:15:45 - HelloAndroid]

去查詢過其他相關討論區說明 , 發現全部都不是正確解答(包含 Android 的討論區)

後 來重新檢視 Android 的文件 , 它出現一行小小的文字: "Android 不支援 GCJ"

嗯 , 剛剛在啟動 Eclipse 3.4 (ganymede) 時有看到說電腦有 GCJ 之類的提示說明

很不幸的 我的Ubuntu上面有安裝 GCJ (有點忘記是 UBuntu 預設安裝 , 還是我自己手賤裝上去的)

原因:
Android SDK 不支援 GCJ

解決方法:
使用Synaptic 套件管理程式 , 搜尋 gcj , 把所有有關 gcj 的套件整個徹底移除之後

重新啟動 Eclipse , 建立 Android Project 去測試 HelloAndroid 整個就是沒有問題