Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8c94ea7

Browse files
author
Erwin Jansen
committedAug 28, 2020
Update documentation for TURN usage.
This updates the documentation and adds more details on how to configure your own TURN server if needed. A TURN server is needed if the emulator is hidden behind a VPN that does not permit UDP packets to go through. We modify the launcher to make it easier to pass in the turn configuration at container launch time.
1 parent e7577ac commit 8c94ea7

File tree

8 files changed

+487
-136
lines changed

8 files changed

+487
-136
lines changed
 

‎README.md

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a set of minimal scripts to run the emulator in a container for various
44
systems such as Docker, for external consumption. The scripts are compatible
55
with both Python version 2 and 3.
66

7-
*Note that this is still an experimental feature and we recommend installing
7+
\*Note that this is still an experimental feature and we recommend installing
88
this tool in a [python virtual environment](https://docs.python.org/3/tutorial/venv.html).
99
Please file issues if you notice that anything is not working as expected.
1010

@@ -19,28 +19,28 @@ following requirements:
1919
installing the command line tools is sufficient.
2020
- [Docker](https://docs.docker.com/v17.12/install/) must be installed. Make
2121
sure you can run it as [non-root
22-
user]((https://docs.docker.com/install/linux/linux-postinstall/))
22+
user](https://docs.docker.com/install/linux/linux-postinstall/)
2323
- [Docker-compose](https://docs.docker.com/compose/install/) must be installed.
2424
- KVM must be available. You can get access to KVM by running on "bare metal",
2525
or on a (virtual) machine that provides nested virtualization. If you are planning to run
2626
this in the cloud (gce/azure/aws/etc..) you first must make sure you have
2727
access to KVM. Details on how to get access to KVM on the various cloud
2828
providers can be found here:
2929

30-
- AWS provides [bare
31-
metal](https://aws.amazon.com/about-aws/whats-new/2019/02/introducing-five-new-amazon-ec2-bare-metal-instances/)
32-
instances that provide access to KVM.
33-
- Azure: Follow these
34-
[instructions](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nested-virtualization)
35-
to enable nested virtualization.
36-
- GCE: Follow these
37-
[instructions](https://cloud.google.com/compute/docs/instances/enable-nested-virtualization-vm-instances)
38-
to enable nested virtualization.
30+
- AWS provides [bare
31+
metal](https://aws.amazon.com/about-aws/whats-new/2019/02/introducing-five-new-amazon-ec2-bare-metal-instances/)
32+
instances that provide access to KVM.
33+
- Azure: Follow these
34+
[instructions](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nested-virtualization)
35+
to enable nested virtualization.
36+
- GCE: Follow these
37+
[instructions](https://cloud.google.com/compute/docs/instances/enable-nested-virtualization-vm-instances)
38+
to enable nested virtualization.
3939

4040
Keep in mind that you will see reduced performance if you are making use of
4141
nested virtualization. The containers have been tested under Debian and Ubuntu running kernel 5.2.17.
4242

43-
*NOTE: The images will not run in docker on mac or windows*
43+
_NOTE: The images will not run in docker on mac or windows_
4444

4545
# Quick start with hosted containers.
4646

@@ -49,8 +49,10 @@ We now host a set of containers in a public repository. You can find details abo
4949

5050
```sh
5151
docker run \
52-
-e "ADBKEY=$(cat ~/.android/adbkey)" --device /dev/kvm --publish \
53-
8554:8554/tcp --publish 15555:5555/tcp \
52+
-e ADBKEY="$(cat ~/.android/adbkey)" \
53+
--device /dev/kvm \
54+
--publish 8554:8554/tcp \
55+
--publish 5555:5555/tcp \
5456
us-docker.pkg.dev/android-emulator-268719/images/r-google-x64:30.0.23
5557
```
5658

@@ -60,7 +62,7 @@ starting:
6062
After this you can connect to the device by configuring adb:
6163

6264
```sh
63-
adb connect localhost:15555
65+
adb connect localhost:5555
6466
```
6567

6668
The device should now show up after a while as:
@@ -69,17 +71,19 @@ The device should now show up after a while as:
6971
$ adb devices
7072

7173
List of devices attached
72-
localhost:15555 device
74+
localhost:5555 device
7375
```
7476

7577
If you wish to use this in a script you could do the following:
7678

7779
```sh
7880
docker run -d \
79-
-e "ADBKEY=$(cat ~/.android/adbkey)" --device /dev/kvm --publish \
80-
8554:8554/tcp --publish 15555:5555/tcp \
81+
-e ADBKEY="$(cat ~/.android/adbkey)" \
82+
--device /dev/kvm \
83+
--publish 8554:8554/tcp \
84+
--publish 5555:5555/tcp \
8185
us-docker.pkg.dev/android-emulator-268719/images/r-google-x64:30.0.23
82-
adb connect localhost:15555
86+
adb connect localhost:5555
8387
adb wait-for-device
8488

8589
# The device is now booting, or close to be booted
@@ -88,7 +92,6 @@ docker run -d \
8892

8993
A more detailed script can be found in [run-in-script-example.sh](./run-in-script-example.sh).
9094

91-
9295
# Install in a virtual environment
9396

9497
You can install the python package as follows:
@@ -101,8 +104,7 @@ follows:
101104

102105
emu-docker -h
103106

104-
You will need to accept the android licenses when you are creating images. You will have
105-
to accept the license agreements before you can create docker containers.
107+
You will have to accept the license agreements before you can create docker containers.
106108

107109
## Quick start, interactively creating and running a docker image
108110

@@ -130,8 +132,8 @@ command and check if a device is detected.
130132

131133
Do not forget to stop the docker container once you are done!
132134

133-
Read the [section](#Make-the-emulator-accessible-on-the-web) on making the emulator available on the web to run the emulator
134-
using webrtc
135+
Read the [section](#Make-the-emulator-accessible-on-the-web) on making the
136+
emulator available on the web to run the emulator using webrtc
135137

136138
## Obtaining URLs for emulator/system image zip files
137139

@@ -145,7 +147,7 @@ of:
145147
- Available and currently Docker-compatible system images
146148
- Currently published and advertised emulator binaries
147149

148-
For each system image, the API level, variant, ABI, and URL are displayed. For
150+
For each system image, the API level, variant, ABI, and URL are displayed. For
149151
each emulator, the update channel (stable vs canary), version, host os, and URL
150152
are displayed.
151153

@@ -179,7 +181,7 @@ Example output:
179181
EMU canary 29.0.12 linux https://dl.google.com/android/repository/emulator-linux-5613046.zip
180182

181183
One can then use tools like `wget` or a browser to download a desired emulator
182-
and system image. After the two are obtained, we can build a Docker image.
184+
and system image. After the two are obtained, we can build a Docker image.
183185

184186
Given an emulator zip file and a system image zip file, we can build a directory
185187
that can be sent to `docker build` via the following invocation of `emu-docker`:
@@ -210,13 +212,15 @@ We provide the following run script:
210212

211213
It does the following:
212214

213-
docker run -e "TOKEN=$(cat ~/.emulator_console_auth_token)" -e "ADBKEY=$(cat ~/.android/adbkey)" -e "EMULATOR_PARAMS=${PARAMS}" --device /dev/kvm --publish 8554:8554/tcp --publish 5554:5554/tcp --publish 5555:5555/tcp ${CONTAINER_ID}
214-
215+
docker run -e ADBKEY="$(cat ~/.android/adbkey)" \
216+
--device /dev/kvm \
217+
--publish 8554:8554/tcp \
218+
--publish 5555:5555/tcp <docker-image-id>
215219

216220
- Sets up the ADB key, assuming one exists at ~/.android/adbkey
217221
- Uses `--device /dev/kvm` to have CPU acceleration
218222
- Starts the emulator in the docker image with its gRPC service, forwarding the
219-
host ports 8554/6664/5555 to container ports 8554/5554/5555 respectively.
223+
host ports 8554/5555 to container ports 8554/5555 respectively.
220224
- The gRPC service is used to communicate with the running emulator inside the
221225
container.
222226

@@ -238,9 +242,9 @@ You can now launch the emulator with the `run-with-gpu.sh` script:
238242

239243
The script is similar as to the one described above with the addition that it will:
240244

241-
- Make all the available gpu's available (`--gpu all`)
242-
- Opens up xhost access for the container
243-
- Enable the domain socket under /tmp/.X11-unix to communicate with hosts X server
245+
- Make all the available gpu's available (`--gpu all`)
246+
- Opens up xhost access for the container
247+
- Enable the domain socket under /tmp/.X11-unix to communicate with hosts X server
244248

245249
Hardware acceleration will significantly improve performance of applications that heavily
246250
rely on graphics. Note that even though we need a X11 server for gpu acceleration there
@@ -260,19 +264,19 @@ We adopted the following naming scheme for images:
260264
Where:
261265

262266
- desert is the desert letter
263-
- sort is one of: *aosp*, *google*, *playstore*
264-
- *aosp*: A basic android open source image
265-
- *google*: A system image that includes access to Google Play services.
266-
- *playstore*: A system image that includes the Google Play Store app and access to Google Play services,
267-
including a Google Play tab in the Extended controls dialog that provides a
268-
convenient button for updating Google Play services on the device.
269-
- abi indicates the underlying CPU architecture, which is one of: *x86*, *x64*, *a32*, *a64*.
267+
- sort is one of: _aosp_, _google_, _playstore_
268+
- _aosp_: A basic android open source image
269+
- _google_: A system image that includes access to Google Play services.
270+
- _playstore_: A system image that includes the Google Play Store app and access to Google Play services,
271+
including a Google Play tab in the Extended controls dialog that provides a
272+
convenient button for updating Google Play services on the device.
273+
- abi indicates the underlying CPU architecture, which is one of: _x86_, _x64_, _a32_, _a64_.
270274
Note that arm images are not hardware accelerated and might not be fast enough.
271275

272-
For example: *q-playstore-x86:29.3.2* indicates a playstore enabled system image with Q running on 32-bit x86.
276+
For example: _q-playstore-x86:29.3.2_ indicates a playstore enabled system image with Q running on 32-bit x86.
273277

274-
*Note: We are in the process of migrating from version number to emulator build numbers,
275-
which are more accurate*
278+
_Note: We are in the process of migrating from version number to emulator build numbers,
279+
which are more accurate_
276280

277281
An example invocation for publishing all Q images to google cloud repo could be:
278282

@@ -283,7 +287,6 @@ An example invocation for publishing all Q images to google cloud repo could be:
283287
Images that have been pushed to a repository can be launched directly from the repository.
284288
For example:
285289

286-
287290
```sh
288291
docker run --device /dev/kvm --publish 8554:8554/tcp --publish 5555:5555/tcp \
289292
us.gcr.io/emulator-project/q-playstore-x86:29.3.2
@@ -315,13 +318,13 @@ composing the following set of docker containers:
315318

316319
- [Envoy](https://www.envoyproxy.io/), an edge and service proxy: The proxy is
317320
responsible for the following:
318-
- Offer TLS (https) using a self signed certificate
319-
- Redirect traffic on port 80 (http) to port 443 (https)
320-
- Act as a [gRPC proxy](https://grpc.io/blog/state-of-grpc-web/) for the
321-
emulator.
322-
- Verifying tokens to permit access to the emulator gRPC endpoint.
323-
- Redirect other requests to the Nginx component which hosts
324-
a [React](https://reactjs.org/) application.
321+
- Offer TLS (https) using a self signed certificate
322+
- Redirect traffic on port 80 (http) to port 443 (https)
323+
- Act as a [gRPC proxy](https://grpc.io/blog/state-of-grpc-web/) for the
324+
emulator.
325+
- Verifying tokens to permit access to the emulator gRPC endpoint.
326+
- Redirect other requests to the Nginx component which hosts
327+
a [React](https://reactjs.org/) application.
325328
- [Nginx](https://www.nginx.com/), a webserver hosting a compiled React App
326329
- [Token Service](js/jwt-provider/README.md) a simple token service that hands out
327330
[JWT](https://en.wikipedia.org/wiki/JSON_Web_Token) tokens to grant access to the emulator.
@@ -333,13 +336,13 @@ In order to run this sample and be able to interact with the emulator you must
333336
keep the following in mind:
334337

335338
- The demo has two methods to display the emulator.
336-
1. Create an image every second, which is displayed in the browser. This
337-
approach will always work, but gives poor performance.
338-
2. Use [WebRTC](https://webrtc.org/) to display the state of the emulator in
339-
real time. This will only work if you are able to create a peer to peer
340-
connection to the server hosting the emulator. This is usually not
341-
a problem when your server is publicly visible, or if you are running the
342-
emulator on your own intranet.
339+
1. Create an image every second, which is displayed in the browser. This
340+
approach will always work, but gives poor performance.
341+
2. Use [WebRTC](https://webrtc.org/) to display the state of the emulator in
342+
real time. This will only work if you are able to create a peer to peer
343+
connection to the server hosting the emulator. This is usually not
344+
a problem when your server is publicly visible, or if you are running the
345+
emulator on your own intranet.
343346

344347
## Requirements
345348

@@ -348,23 +351,15 @@ keep the following in mind:
348351
internal network and expose the http and https ports.
349352
- You will need to create an emulator docker image, as described in the
350353
documentation above.
354+
- Depending on your network you might need [turn](js/turn/README.MD)
351355

352356
## Running the emulator on the web
353357

354-
355358
In order to create the web containers you must have the following tools available:
356359

357-
- A protobuf compiler and headers
358-
- GNUmake
359360
- NodeJS
360-
- Package config
361361
- Npm
362362

363-
On debian based systems you can install these as follows:
364-
365-
sudo apt-get install build-essential nodejs npm libprotoc-dev protobuf-compiler pkg-config
366-
367-
368363
Next you must create a container with the emulator & system image version you wish to
369364
use. For example:
370365

@@ -392,6 +387,7 @@ For example:
392387
```sh
393388
./create_web_container.sh -p user1,passwd1,user2,passwd2,....
394389
```
390+
395391
This will do the following:
396392

397393
- Create a virtual environment
@@ -413,7 +409,6 @@ js/docker/development.yaml as follows:
413409
docker-compose -f js/docker/docker-compose.yaml -f js/docker/development.yaml up
414410
```
415411

416-
417412
Point your browser to [localhost](http://localhost). You will likely get
418413
a warning due to the usage of the self signed certificate. Once you accept the
419414
cert you should be able to login and start using the emulator.
@@ -422,9 +417,10 @@ Keep the following things in mind when you make the emulator accessible over adb
422417

423418
- Port 5555 will be exposed in the container.
424419
- The container must have access to the file: `~/.android/adbkey`. This is
425-
the *PRIVATE* key used by adb.
420+
the _PRIVATE_ key used by adb. Without this you will not be able to access the device
421+
over adb.
426422
- The adb client you use to connect to the container must have access to the
427-
private key (~/.android/adbkey). This is usually the case if you are on the same machine.
423+
private key (~/.android/adbkey). This is usually the case if you are on the same machine.
428424
- You must run: `adb connect ip-address-of-container:5555` before you can
429425
interact with the device. For example:
430426

0 commit comments

Comments
 (0)
This repository has been archived.