ADB and testing Android apps
Being able to run Android apps on a Chromebook is great, it gives users access to the vast Android ecosystem offerings and it gives Android developers the opportunity to reach ChromeOS users.
Developers should make a point to verify their apps on different form factors, since this will help improve users’ experiences. This is why ChromeOS provides Android developers with the tools to deploy and test their apps on Chromebooks.
Whether developers are deploying their Android app directly from ChromeOS (using Android Studio in your Chromebook) or from another device, developers can use ADB to deploy their apps and debug different interactions with Chromebooks. For more details checkout the steps below.
Enable ADB debug
Previously, using ADB on your Chromebook was only possible while in developer mode, which requires powerwashing (resetting) the device and can reduce security. Luckily since Chrome 81, developers can keep their devices out of developer mode and still deploy apps they develop directly in ChromeOS, with the flip of a switch. Here is how:
First, make sure the Chromebook is not in developer mode. Then go to settings and turn on Linux (if you haven’t done so before).
Once Linux is available open the Linux settings and you’ll find a new option ‘Develop Android apps’, open that option.
Toggle enable ADB debugging and the computer will restart.
When the computer restarts you’ll see a message that lets you know that there may be applications that were not downloaded from the app store on the device.
ADB is now available to deploy apps to your Chromebook, run debugging commands and interact directly with the device.
To ensure that your Android app works well on a variety of Chromebook devices and available form factors, Google recommends that you test your app on the following devices:
- An ARM-based Chromebook
- An x86-based Chromebook
- A device with a touchscreen and one without one
- A convertible device; that is, one that can change between a laptop and a tablet
- A device with a stylus
Deploy from ChromeOS
After enabling ADB debugging, you can load an Android app directly onto your ChromeOS device using Android Studio or if you have an APK you can load it using the Terminal.
Deploy with Android Studio
After you have set up Android Studio and ADB as described above, you can push your apps to the Chromebook’s Android container directly from Android Studio.
The Chromebook will appear as an option in the device drop down:
Now you can push your app like any other Android device! The ADB authorization dialog appears the first time you try to push to a new device. After you authorize it, your application will launch in a new window.
That’s it, you can now deploy the app to the Chromebook, test and debug without the hassle of being in developer mode.
Deploy with Terminal
Install ADB if necessary:
Connect to the device:
An authorization popup for USB debugging appears the first time you try to deploy to the device, and you’ll need to allow it.
Install your app from the terminal:
Deploy from another device
If you can’t use the method described above and need to push your app from another device, you can connect the device to ADB using USB or a network address.
Connect to ADB over a network
- Make sure you enabled ADB debugging.
Get the IP address of your Chromebook:
- Click the clock in the bottom-right area of the screen.
- Click the gear icon.
- Click the network type you are connected to (Wi-Fi or Mobile data) then the name of the network.
- Take note of the IP Address.
Connect to your Chromebook:
- Return to your development machine and use ADB to connect to your Chromebook using its IP address:
- On your Chromebook, click Allow when prompted whether you want to allow the debugger. Your ADB session is established.
Troubleshooting ADB debugging over a network
Sometimes the ADB device shows that it’s offline when everything is connected properly. In this case, complete the following steps to troubleshoot the issue:
- Deactivate ADB debugging in Developer options.
- In a terminal window, run
adb kill-server
. - Re-activate the ADB debugging option.
- In a terminal window, attempt to run
adb connect
. - Click Allow when prompted whether you want to allow debugging. Your ADB session is established.
Connect to ADB over USB
To push your APK from another device into the Chromebook via USB, you must start your ChromeOS in developer mode so that you can configure the Chromebook and push apps from the host machine. This is the only method that currently requires Developer Mode, and it only works on a small number of devices. Because of this, it’s recommended to use ADB over the network instead. If you’d still like to proceed, follow these steps to get into developer mode.
- Make sure you enabled ADB debugging.
- Determine if your device supports USB debugging
- Press control+alt+t to start the ChromeOS terminal.
- Type
shell
to get to the bash command shell: - Type the following commands to set up your device:
- After rebooting, open the terminal again and run the following command to enable ADB on the Chromebook’s USB port:
Use this command each time you disconnect and reconnect a USB cable. To ensure your Chromebook is in UFP mode, you can run ectool usbpd <port number>
.
- Plug in a USB cable to a supported port on your device
- Run
adb devices
from the Android SDK platform tools on your host machine to see your Chromebook listed as an ADB supported device - On your Chromebook, click Allow when prompted whether you want to allow the debugger. Your ADB session is established.