|
1 | | -TODO |
| 1 | +# Problem |
2 | 2 |
|
3 | | -# problem |
| 3 | +You want to test your Android Cordova application with [Travis](https://travis-ci.org/) (or any other CI solution). |
| 4 | +And your tests need permission to be granted on emulator. |
| 5 | +For example, permission to access device storage. |
4 | 6 |
|
5 | | -# solution |
| 7 | +**cordova run** command cannot grant permissions. So you cannot run your tests. |
6 | 8 |
|
7 | | -# usage |
| 9 | +If you use [cordova-paramedic](https://github.com/apache/cordova-paramedic), you also out of luck. |
| 10 | + |
| 11 | +# Solution |
| 12 | + |
| 13 | +Add adb-ci to your project: |
8 | 14 |
|
9 | 15 | npm install adb-ci --save-dev |
| 16 | + |
| 17 | +After adding adb-ci, CI build will always run cordova in such a way that it installs your app on emulator with |
| 18 | +all required permissions granted. |
| 19 | + |
| 20 | +So your tests that require permissions will work. |
| 21 | + |
| 22 | +See [cordova-plugin-photo-library](https://github.com/terikon/cordova-plugin-photo-library) for example of usage of adb-ci. |
| 23 | + |
| 24 | +# How it works |
| 25 | + |
| 26 | +adb-ci adds wrapper to adb command inside your project that will be activated when adb runs, by any node tool. |
| 27 | +cordova is one of such tools. Actually, under the hood, crodova runs adb to install and run your app. |
| 28 | + |
| 29 | +The wrapper is installed in node_modules\.bin\adb. This ways, calls to adb will be redirected to adb-ci. |
| 30 | + |
| 31 | +Every call to adb will be passed through by wrapper as is, except **adb install** command. |
| 32 | +The wrapper will add -g parameter to **adb install** call, so installed app will have granted permissions |
| 33 | +(see [adb docs](https://developer.android.com/studio/command-line/adb.html) for details). |
| 34 | + |
| 35 | +- adb-ci will be activated only when CI environment variable is set, so it will not interfere with development machines. |
| 36 | + |
| 37 | +- ANDROID_HOME envrionment variable should be set for adb-ci to work. |
| 38 | + |
| 39 | +That's it. Hope it will be useful to someone. |
0 commit comments