@@ -4,7 +4,7 @@ This is a set of minimal scripts to run the emulator in a container for various
4
4
systems such as Docker, for external consumption. The scripts are compatible
5
5
with both Python version 2 and 3.
6
6
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
8
8
this tool in a [ python virtual environment] ( https://docs.python.org/3/tutorial/venv.html ) .
9
9
Please file issues if you notice that anything is not working as expected.
10
10
@@ -19,28 +19,28 @@ following requirements:
19
19
installing the command line tools is sufficient.
20
20
- [ Docker] ( https://docs.docker.com/v17.12/install/ ) must be installed. Make
21
21
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/ )
23
23
- [ Docker-compose] ( https://docs.docker.com/compose/install/ ) must be installed.
24
24
- KVM must be available. You can get access to KVM by running on "bare metal",
25
25
or on a (virtual) machine that provides nested virtualization. If you are planning to run
26
26
this in the cloud (gce/azure/aws/etc..) you first must make sure you have
27
27
access to KVM. Details on how to get access to KVM on the various cloud
28
28
providers can be found here:
29
29
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.
39
39
40
40
Keep in mind that you will see reduced performance if you are making use of
41
41
nested virtualization. The containers have been tested under Debian and Ubuntu running kernel 5.2.17.
42
42
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 _
44
44
45
45
# Quick start with hosted containers.
46
46
@@ -49,8 +49,10 @@ We now host a set of containers in a public repository. You can find details abo
49
49
50
50
``` sh
51
51
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 \
54
56
us-docker.pkg.dev/android-emulator-268719/images/r-google-x64:30.0.23
55
57
```
56
58
@@ -60,7 +62,7 @@ starting:
60
62
After this you can connect to the device by configuring adb:
61
63
62
64
``` sh
63
- adb connect localhost:15555
65
+ adb connect localhost:5555
64
66
```
65
67
66
68
The device should now show up after a while as:
@@ -69,17 +71,19 @@ The device should now show up after a while as:
69
71
$ adb devices
70
72
71
73
List of devices attached
72
- localhost:15555 device
74
+ localhost:5555 device
73
75
```
74
76
75
77
If you wish to use this in a script you could do the following:
76
78
77
79
``` sh
78
80
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 \
81
85
us-docker.pkg.dev/android-emulator-268719/images/r-google-x64:30.0.23
82
- adb connect localhost:15555
86
+ adb connect localhost:5555
83
87
adb wait-for-device
84
88
85
89
# The device is now booting, or close to be booted
@@ -88,7 +92,6 @@ docker run -d \
88
92
89
93
A more detailed script can be found in [ run-in-script-example.sh] ( ./run-in-script-example.sh ) .
90
94
91
-
92
95
# Install in a virtual environment
93
96
94
97
You can install the python package as follows:
@@ -101,8 +104,7 @@ follows:
101
104
102
105
emu-docker -h
103
106
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.
106
108
107
109
## Quick start, interactively creating and running a docker image
108
110
@@ -130,8 +132,8 @@ command and check if a device is detected.
130
132
131
133
Do not forget to stop the docker container once you are done!
132
134
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
135
137
136
138
## Obtaining URLs for emulator/system image zip files
137
139
145
147
- Available and currently Docker-compatible system images
146
148
- Currently published and advertised emulator binaries
147
149
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
149
151
each emulator, the update channel (stable vs canary), version, host os, and URL
150
152
are displayed.
151
153
@@ -179,7 +181,7 @@ Example output:
179
181
EMU canary 29.0.12 linux https://dl.google.com/android/repository/emulator-linux-5613046.zip
180
182
181
183
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.
183
185
184
186
Given an emulator zip file and a system image zip file, we can build a directory
185
187
that can be sent to ` docker build ` via the following invocation of ` emu-docker ` :
@@ -210,13 +212,15 @@ We provide the following run script:
210
212
211
213
It does the following:
212
214
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>
215
219
216
220
- Sets up the ADB key, assuming one exists at ~ /.android/adbkey
217
221
- Uses ` --device /dev/kvm ` to have CPU acceleration
218
222
- 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.
220
224
- The gRPC service is used to communicate with the running emulator inside the
221
225
container.
222
226
@@ -238,9 +242,9 @@ You can now launch the emulator with the `run-with-gpu.sh` script:
238
242
239
243
The script is similar as to the one described above with the addition that it will:
240
244
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
244
248
245
249
Hardware acceleration will significantly improve performance of applications that heavily
246
250
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:
260
264
Where:
261
265
262
266
- 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 _ .
270
274
Note that arm images are not hardware accelerated and might not be fast enough.
271
275
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.
273
277
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 _
276
280
277
281
An example invocation for publishing all Q images to google cloud repo could be:
278
282
@@ -283,7 +287,6 @@ An example invocation for publishing all Q images to google cloud repo could be:
283
287
Images that have been pushed to a repository can be launched directly from the repository.
284
288
For example:
285
289
286
-
287
290
``` sh
288
291
docker run --device /dev/kvm --publish 8554:8554/tcp --publish 5555:5555/tcp \
289
292
us.gcr.io/emulator-project/q-playstore-x86:29.3.2
@@ -315,13 +318,13 @@ composing the following set of docker containers:
315
318
316
319
- [ Envoy] ( https://www.envoyproxy.io/ ) , an edge and service proxy: The proxy is
317
320
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.
325
328
- [ Nginx] ( https://www.nginx.com/ ) , a webserver hosting a compiled React App
326
329
- [ Token Service] ( js/jwt-provider/README.md ) a simple token service that hands out
327
330
[ 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
333
336
keep the following in mind:
334
337
335
338
- 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.
343
346
344
347
## Requirements
345
348
@@ -348,23 +351,15 @@ keep the following in mind:
348
351
internal network and expose the http and https ports.
349
352
- You will need to create an emulator docker image, as described in the
350
353
documentation above.
354
+ - Depending on your network you might need [ turn] ( js/turn/README.MD )
351
355
352
356
## Running the emulator on the web
353
357
354
-
355
358
In order to create the web containers you must have the following tools available:
356
359
357
- - A protobuf compiler and headers
358
- - GNUmake
359
360
- NodeJS
360
- - Package config
361
361
- Npm
362
362
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
-
368
363
Next you must create a container with the emulator & system image version you wish to
369
364
use. For example:
370
365
@@ -392,6 +387,7 @@ For example:
392
387
``` sh
393
388
./create_web_container.sh -p user1,passwd1,user2,passwd2,....
394
389
```
390
+
395
391
This will do the following:
396
392
397
393
- Create a virtual environment
@@ -413,7 +409,6 @@ js/docker/development.yaml as follows:
413
409
docker-compose -f js/docker/docker-compose.yaml -f js/docker/development.yaml up
414
410
```
415
411
416
-
417
412
Point your browser to [ localhost] ( http://localhost ) . You will likely get
418
413
a warning due to the usage of the self signed certificate. Once you accept the
419
414
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
422
417
423
418
- Port 5555 will be exposed in the container.
424
419
- 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.
426
422
- 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.
428
424
- You must run: ` adb connect ip-address-of-container:5555 ` before you can
429
425
interact with the device. For example:
430
426
0 commit comments