顯示具有 emulator 標籤的文章。 顯示所有文章
顯示具有 emulator 標籤的文章。 顯示所有文章

2017年3月8日 星期三

how to open android emulator manually

Android emulator is required when developing react-native. In this article, we will discuss how to open android emulator manually.

You can refer installation process described by react as following
https://facebook.github.io/react-native/docs/getting-started.html

It mentions that emulator manager can be invoked by

   android avb  

However, it is unavailable for newly version of Android Studio and it shows



What happen if we ignore the above and execute react-native run-android ?


No doubt, errors show to break my heart. React tells you that running android emulator is required for running react-native android app.

In order to solve the problem, you have to find android first. In mac, it would be
   ~/Library/Android/sdk/tools   

then run 
   emulator -list-avds   

If you have completed installation process of android studio and configured emulator properly, you will show available device name.

* If it does not display any device, you must config emulator device from android studio

next run
    emulator -avd <device name>    

Please replace <device name> as your available devices, for example
     emulator -avd Nexus_5_API_25    

then, emulator will be invoked


After booting, you can run react-native app by executing
    react-native run-andriod    

* about :app:installDebug FAILED, please check whether VM is running in your environment such as Docker. Before you start android emulator, please stop those VMs




如何開啟 Android 模擬器

開發 React-native 會需要用到 android 模擬器,安裝步驟可參考
https://facebook.github.io/react-native/docs/getting-started.html

文中有提到可以以下列指令啟動模擬器管理員

  android avd    

不過,新版的 android studio 安裝完成之後,已不支援。如果執行上述指令會看到


如果忽略上面的步驟,直接透過 CLI (react-native run-android) 執行 android app


react-native 會提示你必須要執行 android 模擬器

解決上述問題,請先找到 android sdk 安裝位置,在mac的位置是

   ~/Library/Android/sdk/tools     


先執行

   emulator -list-avds     

如果可以看到裝置名稱表示有可用的裝置,如果沒有請開啟 android studio 新增一個模擬器

再執行

   emulator -avd <裝置名稱>     

請將 <裝置名稱> 置換成可用的裝置名稱,例如

   emulator -avd Nexus_5_API_25     

如果一切順利的話,android 模擬器就會開始運行

完成開機後就可以直行 react-native run-android 測試 react-native app

*:app:installDebug FAILED :當模擬器無法開啟時,請確認是否有其他VM正在執行。例如 Docker,請先關閉其他VM後再執行 android 模擬器