Skip to content

Commit b4349cd

Browse files
Added documentation for Install application from APK (#31)
Co-authored-by: Priyansh Garg <[email protected]>
1 parent 5c4931a commit b4349cd

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Installing an application from APK
2+
3+
## Introduction
4+
5+
This guide will show you how to install an application from an APK file on an Android emulator or a real device.
6+
7+
## Prerequisites
8+
9+
- Setup Android Emulator using [mobile-helper-tool](https://github.com/nightwatchjs/mobile-helper-tool): `npx @nightwatch/mobile-helper android`.
10+
- APK file of the application you want to install
11+
12+
### Android Device Bridge (adb)
13+
14+
The whole process is done using `adb` command line tool. So, you would need to make sure that `adb` is available from your terminal. You can check this by running `adb --version`.
15+
16+
If `adb` is not available directly, you can either add its location to your `PATH` environment variable, or `cd` to the location where the `adb` binary is present and use it directly from there.
17+
18+
For both the cases, you'd need the location where you've setup your Android SDK, which you can get that by running `npx @nightwatch/mobile-helper android` again:
19+
20+
![Alt text](image.png)
21+
22+
The `adb` binary will be present in the `platform-tools` sub-directory of your Android SDK setup location from above. Eg: `/path/to/Android/sdk/platform-tools/`.
23+
24+
### Adding `adb` location to `PATH`
25+
26+
Add the path of `platform-tools` directory to your `PATH` environment variable.
27+
28+
**Linux/Mac**:
29+
30+
Add the below command at the end of your `~/.bashrc` or `~./bash_profile` file and restart the terminal.
31+
32+
```bash
33+
export PATH=$PATH:/path/to/Android/sdk/platform-tools/
34+
```
35+
36+
**Windows**:
37+
38+
Add the below path to your `PATH` environment variable in the Control Panel and restart the terminal.
39+
40+
```bash
41+
\path\to\Android\sdk\platform-tools\
42+
```
43+
44+
### Using `adb` directly
45+
46+
To use `adb` directly (without adding it to `PATH`), simply go to the directly where the binary is present and use it as follows:
47+
48+
```bash
49+
cd /path/to/Android/sdk/platform-tools/
50+
51+
# for windows
52+
adb.exe --version
53+
54+
# for mac/linux
55+
./adb --version
56+
```
57+
58+
## Assumptions
59+
60+
- APK path is `/path/to/your/app.apk`
61+
- Application package name is `your.app.package`
62+
63+
## Steps
64+
65+
### Check if device is connected
66+
67+
```bash
68+
adb devices
69+
```
70+
71+
### Install the application
72+
73+
```bash
74+
adb install /path/to/your/app.apk
75+
```
76+
77+
### Verify the installation
78+
79+
```bash
80+
adb shell pm list packages -f your.app.package
81+
```
82+
83+
**Note:** If the don't know the exact name of your package, you can use `grep` to find it from the list of installed packages. `grep` comes pre-installed on Linux and Mac terminals.
84+
85+
```bash
86+
adb shell pm list packages -f | grep package_name
87+
```
88+
89+
### Overwrite the existing application
90+
91+
If you want to overwrite the existing application with the new APK, you can use the `-r` option with the `install` command.
92+
93+
```bash
94+
adb install -r /path/to/your/app.apk
95+
```
96+
97+
### Remove the application
98+
99+
```bash
100+
adb uninstall your.app.package
101+
```
102+
103+
### Install the application on a specific device
104+
105+
If you have multiple devices/emulators connected to your adb, you will get an error when you try to install the application.
106+
You need to specify the device on which you want to install the application.
107+
108+
This is not just for installation, you need to specify the device for any `adb` command you run.
109+
110+
To install the application on a specific device, you need to specify the device using the `-s` option before the `install` command.
111+
112+
```bash
113+
adb -s <device_id> install /path/to/your/app.apk
114+
```
115+
116+
You can get the device id by running the below command.
117+
118+
```bash
119+
adb devices
120+
```
121+
122+
```bash
123+
# Output of adb devices
124+
List of devices attached
125+
emulator-5554 device
126+
emulator-5556 device
127+
```
128+
129+
Here, `emulator-5554` and `emulator-5556` are the device ids.

0 commit comments

Comments
 (0)