Android模擬器應用程序允許我們直接從Linux系統(tǒng)運行Android應用程序或游戲,本文介紹在Ubuntu Linux 18.04系統(tǒng)中安裝Anbox的方法,包括其他Linux發(fā)行版上的安裝方法,并且介紹啟動及應用Anbox來運行Android應用程序。
Anbox簡介
Anbox是一種基于容器的方法,用于在常規(guī)GNU/Linux系統(tǒng)上啟動完整的Android系統(tǒng),它是新的和現(xiàn)代的模擬器。相似但不同的項目還有Shashlik和Genimobile等。此方法使用snapcraft,同樣可以按著QQ和微信等,也可以安裝機器人操作系統(tǒng)ROS 1和2。
由于Anbox將核心Android操作系統(tǒng)放入使用Linux命名空間(LXE)的容器中,因此訪問已安裝的應用程序時不會出現(xiàn)慢速。Anbox將允許你在Linux系統(tǒng)上運行Android而不會降低虛擬化的速度,因為核心Android操作系統(tǒng)已經(jīng)放入使用Linux命名空間(LXE)的容器中。
Android容器無法直接訪問任何硬件,所有硬件訪問都通過主機上的anbox守護程序進行。
每個應用程序?qū)⒃谝粋€單獨的窗口中打開,就像其他本機系統(tǒng)應用程序一樣,它可以在啟動器中顯示。
1、使用snap方式安裝Anbox,只需要你的系統(tǒng)支持snap安裝即可:
安裝Anbox snap非常簡單:
linuxidc@linuxmi:~/www.linuxidc.com$ snap install –devmode –beta anbox
如果尚未登錄Ubuntu Store,則snap命令會要求你使用sudo snap …以便安裝snap:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo snap install –devmode –beta anbox
[sudo] linuxidc 的密碼:
anbox (beta) 4-56c25f1 from morphis installed
目前我們需要使用–devmode,因為Anbox snap尚未完全限制,上游snapd項目的工作已經(jīng)開始,以獲得對完全禁閉的支持。
作為使用–devmode的作用,snap不會自動更新,要更新到更新版本,可以運行:
linuxidc@linuxmi:~/www.linuxidc.com$ snap refresh –beta –devmode anbox
有關(guān)當前可用版本的snap的信息可通過以下方式獲得:
linuxidc@linuxmi:~/www.linuxidc.com$ snap info anbox
name: anbox
summary: Android in a Box
publisher: morphis
contact: https://anbox.io
license: unset
description: |
Runtime for Android applications which runs a full Android system
in a container using Linux namespaces (user, ipc, net, mount) to
separate the Android system fully from the host.
You can find further details in our documentation at
https://github.com/anbox/anbox/blob/master/README.md
commands:
– anbox
– anbox.android-settings
– anbox.appmgr
– anbox.collect-bug-info
– anbox.shell
services:
anbox.container-manager: simple, enabled, active
snap-id: Nr9K6UJaIOD8wHpDEQl16nabFFt9LLEQ
tracking: beta
refresh-date: today at 09:19 CST
channels:
stable: –
candidate: –
beta: 4-56c25f1 2020-01-02 (186) 391MB devmode
edge: 4-56c25f1 2020-01-02 (186) 391MB devmode
installed: 4-56c25f1 (186) 391MB devmode
2、Anbox包被添加到Ubuntu(Cosmic)和Debian(Buster)存儲庫中,確保在系統(tǒng)中安裝必要的內(nèi)核模塊才能使用Anbox,對于基于Ubuntu的用戶請使用下面PPA安裝,支持Ubuntu 18.04:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo add-apt-repository ppa:morphis/anbox-support
linuxidc@linuxmi:~/www.linuxidc.com$ sudo apt update
linuxidc@linuxmi:~/www.linuxidc.com$ sudo apt install linux-headers-generic anbox-modules-dkms
或者:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo add-apt-repository ppa:morphis/anbox-support
linuxidc@linuxmi:~/www.linuxidc.com$ sudo apt update
linuxidc@linuxmi:~/www.linuxidc.com$ sudo apt install anbox-modules-dkms
安裝anbox-modules-dkms軟件包后,必須手動重新加載內(nèi)核模塊,否則需要重新啟動系統(tǒng):
linuxidc@linuxmi:~/www.linuxidc.com$ sudo modprobe ashmem_linux
linuxidc@linuxmi:~/www.linuxidc.com$ sudo modprobe binder_linux
注:系統(tǒng)/dev目錄中應該有兩個新節(jié)點:
$ ls -1 /dev/{ashmem,binder}
/dev/ashmem
/dev/binder
注:最后對于Debian/Ubuntu系統(tǒng),請使用APT-GET或APT來安裝anbox:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo apt install anbox
3、基于Arch Linux可以使用AUR程序來安裝它,我使用Yay,參考安裝及使用Arch Linux/Manjaro系統(tǒng)中的AUR助手yay:
linuxidc@linuxmi:~/www.linuxidc.com$ yuk -S anbox-git
Anbox的先決條件
默認情況下,Anbox不隨Google Play商店一起提供。
因此,我們需要手動下載每個應用程序(APK)并使用Android Debug Bridge(ADB)進行安裝。
大多數(shù)發(fā)行版存儲庫都可以使用ADB工具,因此我們可以安裝它。
1、對于Debian/Ubuntu系統(tǒng),請使用APT-GET或APT來安裝ADB:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo apt install android-tools-adb
2、對于Fedora系統(tǒng),使用DNF安裝ADB:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo dnf install android-tools
3、對于基于Arch Linux的系統(tǒng),請使用Pacman安裝ADB:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo pacman -S android-tools
4、對于openSUSE Leap系統(tǒng),使用Zypper安裝ADB:
linuxidc@linuxmi:~/www.linuxidc.com$ sudo zypper install android-tools
下載Android應用程序及啟動Anbox的方法
1、在哪下載Android應用程序
由于你無法使用Play商店,因此必須從可信站點(如APKMirror)下載APK包,然后手動安裝它。
2、啟動Anbox的方法
可以從Dash啟動Anbox,這是默認Anbox的外觀:
將應用程序推入Anbox
我們需要手動安裝它。
首先,需要啟動ADB服務器,請運行以下命令:
linuxidc@linuxmi:~/www.linuxidc.com$ adb devices
通用語法:
linuxidc@linuxmi:~/www.linuxidc.com$ adb install mingzi.apk
安裝一個Android應用(如下圖):
linuxidc@linuxmi:~/www.linuxidc.com$ adb install ‘linuxidc.com.apk’
Success
卸載Anbox的方法
以下方法僅限使用snap來安裝Anbox。如果要從系統(tǒng)中刪除Anbox,首先必須刪除snap。
注意:從系統(tǒng)中刪除存儲在快照中的所有數(shù)據(jù):
linuxidc@linuxmi:~/www.linuxidc.com$ snap remove anbox
刪除快照后,還必須刪除已安裝的內(nèi)核模塊(如果安裝的話):
linuxidc@linuxmi:~/www.linuxidc.com$ sudo apt install ppa-purge
linuxidc@linuxmi:~/www.linuxidc.com$ sudo ppa-purge ppa:morphis/anbox-support
完成后,Anbox將從你的系統(tǒng)中刪除。