iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 5
2
Cloud

Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例系列 第 5

Day05 - Android模擬器部署測試

在進行Android之前, 可以先來看看Android模擬器的類型, 點擊如下紅框所示
http://ithelp.ithome.com.tw/upload/images/20161206/20103333RoOumhFPqw.png

主要以AVD作為區分, AVD指的是Android Virtual Device即Android原生的模擬器, 非AVD為Microsoft自己出的Android的模擬器, 據說是嫌原生的太慢, 自己弄了一個出來跑在Hyper-V裡執行速度比原生的好很多, 底下就這兩類做測試.

與之前Windows測試方式相同, 先將Android專案設為起始專案, 先Build, 選擇第一個5” KitKat進行Deploy, 期間會看到這個模擬器被叫起來在Hype-V 裡如下:
http://ithelp.ithome.com.tw/upload/images/20161206/20103333LBmSd7C5um.png

原本以為會跟之前一樣順順跑完, 誰知天不從人願, 事情果然沒這麼簡單, 出現底下錯誤
http://ithelp.ithome.com.tw/upload/images/20161206/20103333YrE3OgFCAI.png

再次拜讀Google大神, 找到這篇, 說是更新即可
https://forums.xamarin.com/discussion/77924/missingmethodexception-android-support-v4-widget-drawerlayout-adddrawerlistener-not-found
開啟NuGet更新如紅框所示
http://ithelp.ithome.com.tw/upload/images/20161206/20103333d2WWaz5MEW.png

但是案情沒這麼單純, 之後在Build還是出現底下錯誤
http://ithelp.ithome.com.tw/upload/images/20161206/20103333684AuMRuV3.png

又要開始當柯南了, 首先檢查一下編譯版本, 需要Android 7.0, 該不會沒裝吧
http://ithelp.ithome.com.tw/upload/images/20161206/20103333VcilxT7hym.png

到Android SDK Manager檢查
http://ithelp.ithome.com.tw/upload/images/20161206/20103333za8JKH6hC2.png

BINGO!果然沒裝阿 @_@
http://ithelp.ithome.com.tw/upload/images/20161206/20103333OelNnOkk4y.png

接著到底下網址看一下Android 7.0配置, 需要JDK 1.8
https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.0/
http://ithelp.ithome.com.tw/upload/images/20161206/20103333rv2n71HohV.png

再檢查一下JDK, Visual Studio安裝時, 只裝了JDK 1.7
http://ithelp.ithome.com.tw/upload/images/20161206/20103333eNSqlKsaoO.png

補齊上述兩點之後, 根據以前跟Java JDK的奮戰經驗, 安裝完畢之後, 都會習慣重新開機. 之後在Visual Studio裡先Clean, 再Build確認一切沒有問題, 最後按下Deploy
http://ithelp.ithome.com.tw/upload/images/20161206/20103333roDmdeF3lr.png

搞了幾個小時, 終於成功部署, 真的是很蛋疼啊 囧rz

接下來採用AVD來Deploy
http://ithelp.ithome.com.tw/upload/images/20161206/20103333CwxRs8fTSy.png

在Deploy過程中, 會跳出底下這個視窗, Google也知道預設的這個AVD被人嫌到不行, 建議新增一個x86 based的AVD會快10倍, 等等也來測試這個部分
http://ithelp.ithome.com.tw/upload/images/20161206/201033335M3NDFXJtL.png

成功部署後如下圖
http://ithelp.ithome.com.tw/upload/images/20161206/20103333RAoBmmxz4H.png

緊接著測試x86 based的AVD, 點擊Android Emulator如下所示
http://ithelp.ithome.com.tw/upload/images/20161206/2010333339hWTiDzfH.png

點擊Create AVD來新增一個新的模擬器
http://ithelp.ithome.com.tw/upload/images/20161206/201033339UJxoibSLA.png

設定如下圖所示
http://ithelp.ithome.com.tw/upload/images/20161206/20103333aDfoEpAZQj.png

點擊Start測試看看
http://ithelp.ithome.com.tw/upload/images/20161206/20103333tnNFwHOeOa.png

果不其然又有問題, x86 based會跟Hyper-V起衝突, 必須停用Hyper-V
http://ithelp.ithome.com.tw/upload/images/20161206/20103333ing5aW7UFv.png

點擊Windows Power Shell, 並以管理員身分執行
http://ithelp.ithome.com.tw/upload/images/20161206/201033331mjhx4mKlt.png

輸入底下指令關閉hypervisor並重新開機才會生效:
bcdedit /set hypervisorlaunchtype off
http://ithelp.ithome.com.tw/upload/images/20161206/201033335Yy0Rh8wqQ.png

接著回到Visual Studio, 選擇剛建好的AVD進行Deploy
http://ithelp.ithome.com.tw/upload/images/20161206/20103333QmOweVGAKH.png

WTF有完沒完啊, 又跑出Error >”<, 看了錯誤訊息是Intel HAXM沒有安裝
http://ithelp.ithome.com.tw/upload/images/20161206/20103333x5JhTy1Izp.png

點擊Android SDK Manager
http://ithelp.ithome.com.tw/upload/images/20161206/20103333c6CM7zOE8b.png

在Extra選項裡勾選Intel x86 Emulator Accelerator進行安裝
http://ithelp.ithome.com.tw/upload/images/20161206/20103333e2iwQa8DZz.png

到Android SDK目錄裡找到intelhaxm-android.exe, 點擊進行安裝
http://ithelp.ithome.com.tw/upload/images/20161206/20103333n6qff5TYd3.png

安裝過程皆選擇下一步到底
http://ithelp.ithome.com.tw/upload/images/20161206/20103333HtcUfktLrH.png

最後再Deploy, 終於出現部署成功畫面如下, 速度果然飛快啊~
http://ithelp.ithome.com.tw/upload/images/20161206/201033331sDavbScaa.png

後記, Android模擬器怎麼這麼麻煩啊@_@


上一篇
Day04 - Windows 8.1 Phone 實機測試
下一篇
Day06 - Android實機部署測試
系列文
Xamarin.Forms, ASP.NET Core WEB API搭配AZURE服務與資料庫服務整合應用實例32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
eric19740521
iT邦新手 1 級 ‧ 2021-03-18 05:36:38

可以用b4a開發
開發速度比較快

arksu iT邦新手 2 級 ‧ 2021-03-18 09:11:41 檢舉

也許吧, 但是Xamrain.Forms的好處就是跨平台, 且可共用C#的Library, 在多人開發實容易切專案或是Component來開發~

請問一下
VS版本你是用哪一個版本
有用linux開發C#程式嗎??

thx

arksu iT邦新手 2 級 ‧ 2021-03-18 18:51:31 檢舉

若是要在linux寫C#程式, 建議裝VS CODE

我要留言

立即登入留言