You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -11,218 +11,28 @@ sidebar_label: Developing for Android
11
11
/>
12
12
</head>
13
13
14
-
This guide covers how to run and debug Ionic apps on Android emulators and devices using [Capacitor](../reference/glossary.md#capacitor) or [Cordova](../reference/glossary.md#cordova). Android apps can be developed on Windows, macOS, and Linux.
14
+
import DocsCard from '@components/global/DocsCard';
15
+
import DocsCards from '@components/global/DocsCards';
15
16
16
-
## Android Studio
17
+
:::info Looking for the legacy Android guide?
17
18
18
-
[Android Studio](https://developer.android.com/studio/) is the IDE for creating native Android apps. It includes the [Android SDK](../reference/glossary.md#android-sdk), which will need to be configured for use in the command line.
19
+
The Developing for Android guide has officially migrated to the [Capacitor documentation for Android](https://capacitorjs.com/docs/android). If you need to access the legacy documentation, you can find it under the [legacy developing for Android guide](/docs/v6/developing/android).
19
20
20
-
Android Studio is also used to [create Android virtual devices](android.md#creating-an-android-virtual-device), which are required for the Android emulator. Ionic apps can also be [launched to a device](android.md#set-up-an-android-device).
21
-
22
-
:::note
23
-
We don't recommend using Android Studio for _developing_ Ionic apps. Instead, it should only really be used to build and run your apps for the native Android platform and to manage the Android SDK and virtual devices.
24
-
:::
25
-
26
-
### Installing Android Studio
27
-
28
-
Download Android Studio from the <ahref="https://developer.android.com/studio/"target="_blank">Android website</a>. More detailed installation instructions can be found in the <ahref="https://developer.android.com/studio/install"target="_blank">User Guide</a>.
29
-
30
-
### Installing the Android SDK
31
-
32
-
Once installed, open Android Studio. The IDE should detect that the Android SDK needs to be installed. In the **SDK Components Setup** screen, finish installing the SDK. Keep note of the **Android SDK Location**.
33
-
34
-

35
-
36
-
By default, the latest stable SDK Platform is installed, which includes a collection of packages required to target that version of Android.
37
-
38
-
To install system images and other minor SDK platform packages, you may need to ensure **Show Package Details** is checked at the bottom of the SDK Manager.
39
-

40
-
41
-
For future reference, the Android SDK can be managed with Android Studio from the context menu at the top right of the Android Studio welcome screen (select **SDK Manager**) or **Tools**»**SDK Manager** inside Android projects.
42
-
43
-
### Configuring Command Line Tools
44
-
45
-
The Android SDK ships with <ahref="https://developer.android.com/studio/command-line/"target="_blank">useful command-line tools</a>. Before they can be used, some environment variables must be set. The following instructions are for macOS and Linux. For Windows, check the documentation on setting and persisting environment variables in terminal sessions.
46
-
47
-
In `~/.bashrc`, `~/.bash_profile`, or similar shell startup scripts, make the following modifications:
48
-
49
-
1. Set the `ANDROID_SDK_ROOT` environment variable. This path should be the **Android SDK Location** used in the previous section. To find the SDK Location in Android Studio, click **File** > **Project Structure**. Select **SDK Location** in the left pane. The path is shown under **Android SDK location**.
2. Add the Android SDK command-line directories to `PATH`. Each directory corresponds to the category of <ahref="https://developer.android.com/studio/command-line/"target="_blank">command-line tool</a>.
For `apksigner` and `zipalign`, `$ANDROID_SDK_ROOT/build-tools<version>` must also be added to `PATH`.
68
-
:::
69
-
70
-
### Creating an Android Virtual Device
71
-
72
-
Android Virtual Devices (AVDs) are blueprints that the Android emulator uses to run the Android OS. The following documentation is a quick way to get the Android emulator set up. For more detailed instructions and information, see <ahref="https://developer.android.com/studio/run/managing-avds"target="_blank">the Android documentation</a>.
73
-
74
-
AVDs are managed with the Virtual Device Manager. In the Android Studio welcome screen, the context menu at the top right, then **Virtual Device Manager**. The Virtual Device Manager can also be opened inside Android projects in the **Tools**»**Device Manager** menu.
Click **Create Virtual Device** and select a suitable device definition. If unsure, choose **Pixel 2**. Then, select a suitable system image. If unsure, choose **Pie** (API 28) with Google Play services. See <ahref="https://en.wikipedia.org/wiki/Android_version_history"target="_blank">Android version history</a> for information on Android versions.
79
-
80
-
Once the AVD is created, launch the AVD into the Android emulator. Keeping the emulator running is the best way to ensure detection while developing Ionic apps for Android.
Actual Android hardware can also be used for Ionic app development. But first, the device must be set up for development. The following documentation is a quick way to set up Android devices for development. For more detailed instructions and information, see <ahref="https://developer.android.com/studio/run/device"target="_blank">the Android documentation</a>.
89
-
90
-
1. Enable USB debugging on the device. Open **Settings**, navigate to **Developer options**, and enable **USB debugging**. The **Developer options** menu may need to be enabled first. See <ahref="https://developer.android.com/studio/debug/dev-options"target="_blank">the Android documentation</a> for instructions.
91
-
1. Ensure the device has permission to connect to the computer. For macOS, no additional setup is required. For Windows, <ahref="https://developer.android.com/studio/run/oem-usb"target="_blank">install the OEM USB drivers</a>.
92
-
93
-
Verify the connection works by connecting the device to the computer with a USB cable and using the following command:
94
-
95
-
```shell
96
-
adb devices
97
-
```
98
-
99
-
The device should be listed. See the full <ahref="https://developer.android.com/studio/command-line/adb"target="_blank">`adb` documentation</a> for troubleshooting and detailed information.
100
-
101
-
## Cordova Setup
102
-
103
-
Additional setup is required for Cordova to support programmatic builds. This section is not necessary for Capacitor.
104
-
105
-
### Java
106
-
107
-
Native Android apps are compiled with the <ahref="https://java.com/en/"target="_blank">Java</a> programming language. Download the <ahref="https://www.oracle.com/java/technologies/javase-jdk11-downloads.html"target="_blank">Java Development Kit (JDK) 11</a> if you are using **`cordova-android`**`10.0.0` or greater.
108
-
109
-
:::note
110
-
If you are using any version of **`cordova-android`** below `10.0.0`, install the <ahref="https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html"target="_blank">Java Development Kit (JDK) 8</a>.
111
-
:::
112
-
113
-
### Gradle
114
-
115
-
<ahref="https://gradle.org/"target="_blank">
116
-
Gradle
117
-
</a> is the build tool used in Android apps and must be installed separately. See the <a
118
-
href="https://gradle.org/install/"
119
-
target="_blank"
120
-
>
121
-
install page
122
-
</a> for details.
123
-
124
-
## Project Setup
125
-
126
-
Before apps can be deployed to Android simulators and devices, the native project must be configured.
127
-
128
-
1.**Perform an Ionic build, if you haven't already.**
129
-
130
-
```
131
-
$ ionic build
132
-
```
133
-
134
-
2.**Generate the native project, if it does not already exist.**
135
-
136
-
For Capacitor, run the following:
137
-
138
-
```shell
139
-
$ ionic capacitor add android
140
-
```
141
-
142
-
For Cordova, run the following:
143
-
144
-
```shell
145
-
$ ionic cordova prepare android
146
-
```
147
-
148
-
3.**Set the [Package ID](../reference/glossary.md#package-id).**
149
-
150
-
For Capacitor, open the `capacitor.config.json` file and modify the `appId` property.
151
-
152
-
For Cordova, open the `config.xml` file and modify the `id` attribute of the root element, `<widget>`. See [the Cordova documentation](https://cordova.apache.org/docs/en/latest/config_ref/#widget) for more information.
153
-
154
-
## Running with Capacitor
155
-
156
-
Capacitor uses Android Studio to build and run apps to simulators and devices.
157
-
158
-
1.**Develop the Ionic app and sync it to the native project.**
159
-
160
-
With each meaningful change, Ionic apps must be built into web assets before the change can appear on Android simulators and devices. The web assets then must be copied into the native project. Luckily, this process is made easy with a single Ionic CLI command.
161
-
162
-
```shell
163
-
$ ionic capacitor copy android
164
-
```
165
-
166
-
2.**Run the app on a simulator or device.**
167
-
168
-
You can open the Android Studio Project using:
169
-
170
-
```shell
171
-
$ ionic capacitor open android
172
-
```
173
-
174
-
In Android Studio, click the Run button and then select the target simulator or device.
175
-
176
-

177
-
178
-
### Live reload
179
-
180
-
To start a live-reload server run the following command.
181
-
182
-
```shell
183
-
ionic capacitor run android -l --external
184
-
```
185
-
186
-
When running on a device make sure the device and your development machine are connected to the same network.
187
-
188
-
## Running with Cordova
189
-
190
-
The Ionic CLI can build, copy, and deploy Ionic apps to Android simulators and devices with a single command. It can also spin up a development server, like the one used in `ionic serve`, to provide [live-reload](../reference/glossary.md#livereload) functionality.
191
-
192
-
Run the following to start a long-running CLI process that boots up a live-reload server:
193
-
194
-
```shell
195
-
ionic cordova run android -l
196
-
```
197
-
198
-
Now, when changes are made to the app's source files, web assets are rebuilt and the changes are reflected on the simulator or device without having to deploy again.
199
-
200
-
## Debugging Android Apps
201
-
202
-
Once an app is running on an Android device or emulator, it can be debugged with Chrome DevTools.
203
-
204
-
### Using Chrome DevTools
205
-
206
-
Chrome has web developer tool support for Android simulators and devices. Go to `chrome://inspect` in Chrome while the simulator is running or a device is connected to the computer and **Inspect** the app that needs to be debugged.
207
-
208
-
:::note
209
-
Make sure your application is running on the device or simulator, or it will not show up in the list.
0 commit comments