Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

Start building apps for Chrome OS

Chrome OS devices, such as Chromebooks, now support the Google Play Store and Android apps. This article assumes you have an existing Android app designed for phones or tablets that you want to optimize for Chromebooks. To learn the basics of building Android apps, see Build your first app.

Update your app's manifest file

To get started, update your manifest file to account for some key hardware and software differences between Chromebooks and other devices running Android.

As of Chrome OS version M53, all Android apps that don't explicitly require the android.hardware.touchscreen feature will also work on Chrome OS devices that support the android.hardware.faketouch feature. However, to ensure your app works on all Chromebooks, go to your manifest file and adjust the settings so that the android.hardware.touchscreen feature is not required, as shown in the following example. Removing the requirement for touch input means you should also review your app's support for mouse and keyboard interactions.


    
    

Different hardware devices come equipped with different sets of sensors. Although Android handheld devices often have GPS and accelerometers, these sensors are not guaranteed to be available in every Chromebook. However, there are cases where the functionality of a sensor is provided in another way. For example, Chromebooks may not have GPS sensors, but they still provide location data based on Wi-Fi connections. See the Sensors overview document for an overview of all of the sensors that the Android platform supports. If you want your app to run on Chromebooks regardless of sensor availability, you should update your manifest file so that none of the sensors are required.

Some software features are unsupported on Chromebooks. For example, apps that provide custom IMEs, app widgets, live wallpapers, and app launchers aren't supported and won't be available for installation on Chromebooks. For a complete list of software features that aren't currently supported on Chromebooks, see incompatible software features.

Update your target SDK

By updating the targetSdkVersion attribute to the latest API level available, your app can take advantage of all the improvements in the Android platform. For example, Android 7.0 (API level 24) brings enhancements to multi-window support. It allows you to resize activities with free-form resizing, making them feel more natural. You can also access APIs for drag-and-drop operations across apps and custom mouse cursors.

Check for networking requirements

Chromebooks run the entire Android OS in a container, similar to Docker or LXC. This means that Android will not have direct access to the system's LAN interface. Instead, IPv4 traffic will pass through an internal layer of network address translation (NAT), and IPv6 unicast traffic will be routed through an extra hop. Outbound unicast connections from an Android app to the internet should mostly work as-is; but in general, inbound connections are blocked. Multicast or broadcast packets from Android will not be forwarded to the LAN through the firewall.

As a special exception to the multicast restriction, Chrome OS runs a service that forwards mDNS traffic between Android and the LAN interface, so the standard Network Service Discovery APIs are the recommended way to discover other devices on the LAN segment. After finding a device on the LAN, an Android app can use standard TCP or UDP unicast sockets to communicate with it.

IPv4 connections originating from Android will use the Chrome OS host's IPv4 address. Internally, the Android app will see a private IPv4 address assigned to the network interface. IPv6 connections originating from Android will use a different address from the Chrome OS host, as the Android container will have a dedicated public IPv6 address.

Use cloud and local storage effectively

One of the strongest features of Chromebooks is that users can easily migrate from one device to another. That is, if someone stops using one Chromebook and starts using another, they simply have to sign in, and all of their apps appear.

To further improve this experience, you should back up your app's data to the cloud to enable syncing across devices. That said, apps should not depend on an internet connection for normal operation. Apps should save a user's work locally if the device is offline and sync to the cloud once the device is back online. For example, Google Docs allows users to edit their docs offline and sync the changes to the cloud once the device gets connectivity.

Chromebooks can also be shared among a large number of people, such as in schools. Since local storage is not infinite, entire accounts—together with their storage—can be removed from the device at any point. For educational settings, it's a good idea to keep this scenario in mind.

Update the NDK libraries

If your app uses the Android NDK libraries, and its target SDK version is 23 or higher, ensure that text relocations are removed from both the ARM and x86 versions of your NDK libraries, as they're not compatible in Android 6.0 (API level 23) and higher. By leaving text relocations in your NDK libraries, you may also cause incompatibility errors with Chromebooks, especially when running on a device that uses an x86 architecture.

Sideload your app

To sideload your app onto your Chromebook for testing, you must enter Developer mode on your Chrome OS device and enable unknown sources. See the Putting your Chrome OS Device into Developer Mode document for detailed instructions about moving your device into Developer mode. After your device is in Developer mode, you can go to your Chrome settings and select Enable Unknown Sources under the security in app settings.

After enabling Developer mode, you can load an Android app onto your Chrome OS device using one of several methods. For more details, see the Load your app section of the Loading Apps on Chromebooks page.

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-basedChromebook
  • 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

To view the full list of supported devices, see the Chrome OS device support for apps page.

Debug with ADB

You can use the Android debug bridge (ADB) from your development machine to sideload and debug your app while it runs on a Chrome OS device. You can use USB or a network address to connect your device to ADB.

To use ADB, you must start your Chrome OS in Developer Mode so you can sideload Android apps onto your Chromebook.

After starting in developer mode, complete the following setup steps:

  1. Press Control+D to start your device.
  2. Finish the setup process.
  3. Log into your test account.
  4. Accept the Google Play Store terms and service conditions.

Enable ADB debugging

First, check to see if your device supports USB debugging.

To enable debugging:

  1. Click the clock in the bottom-right area of the screen.
  2. Click the gear icon.
  3. Click the Google Play Store section, then Manage Android preferences. This brings up the Android settings. You might want to right-click on the settings icon in the shelf and pin it there to get faster access in the future.
  4. Scroll down and click About device.
  5. Click Build number seven times to move into Developer mode.
  6. Click the arrow in the top-left area of the window to go back to the main Settings screen.
  7. Click the new Developer options item, activate ADB debugging, and then click OK to allow ADB debugging.

You might also want to optionally select these additional Android developer options for Chrome OS:

  • Allow free window resizing by dragging the border - This option lets you resize the app's window. Use it to to see if the app handles window size changes properly and to make sure that resizing is fast and fluid.
  • Debug information - Displays debugging information for Android applications in the window title bar.

Connect to ADB over USB

  1. Determine if your device supports USB debugging
  2. Press Control+Alt+T to start the Chrome OS terminal.
  3. Type shell to get to the bash command shell:

    crosh> shell
    chronos@localhost / $
    
  4. Type the following commands to set up your device:

    $ sudo crossystem dev_enable_udc=1
    $ sudo reboot
    
  5. After rebooting, open the terminal again and run the following command to enable ADB on the Chromebook's USB port:

    $ sudo ectool usbpd <port number> dr_swap
    

    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>.

  6. Plug in a USB cable to a supported port on your device

  7. Run adb devices from the Android SDK platform tools on your host machine to see your Chromebook listed as an adb supported device

  8. On your Chromebook, click Allow when prompted whether you want to allow the debugger. Your ADB session is established.

Connect to ADB over a network

In order to debug over a network, you must configure the Chrome OS firewall to allow incoming ADB connections:

  1. Press Control+Alt+T to start the Chrome OS terminal.
  2. Type shell to get to the bash command shell:

    crosh> shell
    chronos@localhost / $
    
  3. Type the following commands to set up developer features and enable disk-write access for the firewall settings changes. If you need to enter a sudo password for the chronos user, you can (re)set one by running chromeos-setdevpassword at the VT-2 prompt (Control+Alt+→); you'll need your root password.

    $ sudo crossystem dev_boot_signed_only=0
    $ sudo /usr/libexec/debugd/helpers/dev_features_rootfs_verification
    $ sudo reboot
    
  4. The sudo reboot command restarts your Chromebook. You can press the Tab key to enable autocompletion of file names. You must complete this procedure only once on your Chromebook.

After your device restarts, log in to your test account and type the following command to enable the secure shell and configure the firewall properly:

$ sudo /usr/libexec/debugd/helpers/dev_features_ssh

When the command completes, you can exit out of the shell.

Get the IP address of your Chromebook:

  1. Click the clock in the bottom-right area of the screen.
  2. Click the gear icon.
  3. Click the network type you are connected to (Wi-Fi or Mobile data) then the name of the network.
  4. Take note of the IP Address.

Connect to your Chromebook:

  1. Return to your development machine and use ADB to connect to your Chromebook using its IP address:

    adb connect <ip_address>
    
  2. 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:

  1. Deactivate ADB debugging in Developer options.
  2. In a terminal window, run adb kill-server.
  3. Re-activate the ADB debugging option.
  4. In a terminal window, attempt to run adb connect.
  5. Click Allow when prompted whether you want to allow debugging. Your ADB session is established.

Develop new test cases for your app

First, make sure that the proper manifest flags are specified. These flags include the desired orientation, where setting screenOrientation unspecified is best. If you specify the orientation as landscape, consider using sensorLandscape instead to make sure that the experience on a tablet is optimal. If you have special size or orientation requests you should also consider adding the new meta tags as size or orientation hints—which only affects desktop environments. If you also want to change it on phones, you should specify layout defaultHeight, defaultWidth, or minHeight instead.

If you are interested in specific input device handling for specific device categories, you should specify android.hardware.type.pc to disable the input compatibility mode.

If you are using any kind of networking, make sure that the app is able to reconnect to the network after a connection problem is resolved or the device wakes from sleep mode.

Google recommends checking the Test cases for Android apps on Chrome OS, which you can use in your own test plan. The test cases cover a wide array of common scenarios that Android apps should be prepared for if they are expected to run on Chrome OS devices.

Multi-window and orientation changes

Chrome OS's multi-window environment can make state persistence and recall issues more obvious. You should use onSaveInstanceState() and onRestoreInstanceState() to save and restore your state when appropriate. To test state persistence you should minimize your app for some time, start another resource intensive process and then restore your app to validate that it returns to the state in which you left it.

Test window resizing by pressing the full screen key (F4), maximizing, and restoring. Test free resizing by enabling it in the developer options and checking that your app smoothly resizes without crashing.

If your Chrome OS device supports it, change from laptop into tablet mode to see that everything works as expected. Rotate the device once in tablet mode to test orientation changes. Transition back into laptop mode. Repeat this step a few times.

Make sure that the top bar is not breaking your app by offsetting UI elements or location-based touch input. For Chrome OS devices, make sure that your app does not place important information in the status bar area.

If you are using the camera or other hardware features—like the pen—make sure that it behaves properly when performing the window and device changes as outlined above.