![](/img/trans.png)
[英]Android. How from command line start emulator, deploy apk AND run apk?
[英]Install and Run .apk on Android Emulator from Command Line
我必須在 android 模擬器上從命令行安裝和運行一個應用程序。我已經閱讀了相同的 android 開發人員文檔,並按如下方式實現。
在模擬器上安裝 apk: adb -d emulator-5554 install path/to/my/app.apk
這成功地在正在運行的虛擬機上安裝了 apk。我無法打開已安裝的應用程序,為此我已經嘗試通過命令安裝和一起運行
adb -d install path/to/your/app.apk
,
但此命令顯示錯誤“
錯誤:未找到設備
-等待設備-
我在啟動模擬器后嘗試了該命令,但它仍然顯示正常的錯誤
-d
設備
你需要使用
-e for emulator
要將 apk 安裝到您需要使用的模擬器中
adb -e install c:\myapk.apk
亞行選項
-a - directs adb to listen on all interfaces for a connection
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
-e - directs command to the only running emulator. returns an error if more than one emulator is running.
-s <specific device> - directs command to the device or emulator withthe given
安裝應用程序后,您可以開始使用命令 --- adb shell am start -a android.intent.action.MAIN -n package_name/.main_activity_name
例如: adb shell am start -a android.intent.action.MAIN -n com.example.flash/.MainActivity
要遵循的命令:
adb devices // It will list devices with their Unique id
adb -s "DeviceIdFromListOfDevices" install path+apkName
您已完成安裝。
安裝和運行:
%ANDROID_HOME%\platform-tools\adb install -r path/to/my/app.apk
%ANDROID_HOME%\platform-tools\adb shell am start -a android.intent.action.MAIN -n com.mypack.name/.MainActivity
第一個命令行安裝您的應用程序。 參數-r
刪除預裝版本。 path/to/my/app.apk
將替換為您的真實路徑和 apk 名稱。 第二個命令啟動您的應用程序。 com.mypack.name/.MainActivity
將替換為您的包名稱。
如果您想將模擬器放在所有窗口的前面,您可以附加以下幾行。 將創建一個 Windows 腳本文件。 腳本將被執行,然后文件將被刪除。
echo new ActiveXObject("WScript.Shell").AppActivate("emulator"); > tmp.js
cscript //nologo tmp.js & del tmp.js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.