In this document
Android O introduces several new features and APIs, and includes changes that can affect the behavior of your app even if you change nothing. To help you prepare, this page explains how to perform compatibility testing and how to update your app to use new Android O features:
- Ensure compatibility with Android O
Verify that your app is fully functional on the new version of the platform. At this stage, you do not use new APIs or change your app's
targetSdkVersion, but minor changes might be necessary. - Update your target version and use Android O features
When you are ready to take advantage of the new features of the platform, update your
targetSdkVersionto 26, verify the app continues to function as expected, and then begin using new APIs.
Ensure compatibility with Android O
The objective here is to make sure that your existing app works as-is Android O.
Because some platform changes might affect the way your app behaves, some adjustments
might be necessary, but you do not need to use new APIs or change your
targetSdkVersion.
Prepare a device running Android O
- If you have a compatible device (Pixel, Pixel XL, Pixel C, Nexus 5X, Nexus 6P, or Nexus Player), obtain the Android O system image for your device from the Downloads page, and then follow the instructions to flash your device.
- Or download the Android O system image for the Android Emulator. It's listed in the
SDK Manager under
Android O Preview as Google APIs Intel x86 Atom System Image.
Note: The Android O system image is available for download only from Android Studio 3.0 canary. For more information, see the section below to get the Android O SDK.
Perform compatibility testing
For the most part, testing compatibility with Android O entails the same type of testing you perform when preparing to release your app. This is a good time to review the Core App Quality Guidelines and Best Practices for Testing.
However, there's another aspect to testing: Android O introduces changes to the Android
platform that can affect your app's behavior or break the app altogether, even if you do not change
your targetSdkVersion. For this reason, it is important that you review the key changes
in table 1, and test any fixes that you implement to accommodate the changes.
Table 1. Key changes that affect all apps running on Android O devices.
| Change | Summary | Further reference |
|---|---|---|
| Less frequent background location updates | If your app receives location updates from a background service, it receives less frequent updates on Android O compared to older versions of Android. Specifically, a background service cannot receive location updates more than a few times per hour. However, while your app is in the foreground, the rate of location updates is unchanged. | Background Location Limits |
net.hostname no longer supported
|
Querying the net.hostname system property produces a null result.
|
None |
New exception from send(DatagramPacket) |
The send(DatagramPacket) method throws a SocketException
if the previously executed connect(InetAddress, int) method failed.
|
Behavior Changes: Network and HTTP(S) connectivity |
Proper NullPointerException from
AbstractCollection methods
|
AbstractCollection.removeAll(null) and
AbstractCollection.retainAll(null) now always throw a
NullPointerException;
previously, the NullPointerException was not thrown when the collection was empty.
This change makes the behavior consistent with the documentation.
|
Behavior Changes: Collection handling |
Proper NullPointerException from
Currency.getDisplayName(null)
|
Calling Currency.getDisplayName(null)
throws a NullPointerException.
|
Behavior Changes: Locales and internationalization |
For a more extensive list of behavior changes in Android O, also see Android O Behavior Changes.
Update your target version and use Android O features
This section explains how to enable full support for Android O by updating
your targetSdkVersion to 26 and adding new features available in Android O.
In addition to offering you new APIs, Android O introduces some behavior
changes when you update your targetSdkVersion to 26. Because some behavior changes
might require code changes to avoid breakage, you should first understand how your app might be
affected when you change the targetSdkVersion by reviewing all behavior changes for apps targeting Android O.
Note: The steps described above to ensure platform compatibility are prerequisite to targeting your app to Android O, so be sure you complete those steps first.
Get the Android O SDK
You can get the SDK packages to build your app with Android O using either Android Studio 2.3 or the Android Studio 3.0 preview. However, only Android Studio 3.0 includes tools to help you with Android O features such as adaptive icons and downloadable fonts. If you don't need those features yet, then you can use the stable version of Android Studio 2.3 to build your app with Android O and use the new APIs.
To get setup with either version of Android Studio, follow these steps:
- Launch Android Studio and open the SDK Manager by clicking Tools > Android > SDK Manager.
- In the SDK Platforms tab, check Show Package Details. Below
Android O Preview check the following:
- Android SDK Platform O
- Google APIs Intel x86 Atom System Image (only required for the emulator)
- Switch to the SDK Tools tab and check all items that have updates available (click
each checkbox that shows a dash
). This should include the following that are required:
- Android SDK Build-Tools 26.0.0
- Android SDK Platform-Tools 26.0.0
- Android Emulator 26.0.0
- Click OK to install all the selected SDK packages.
Now you're ready to start building with Android O.
Update your build configuration
Update compileSdkVersion, buildToolsVersion,
targetSdkVersion, and the Support Library version with the following versions:
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
defaultConfig {
targetSdkVersion 26
}
...
}
dependencies {
compile 'com.android.support:appcompat-v7:26.0.0-beta2'
}
// REQUIRED: Google's new Maven repo is required for the latest
// support library that is compatible with Android O
repositories {
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
Remove broadcast receivers from your manifest file
Because Android O introduces new limitations for broadcast receivers, you should remove any broadcast receivers that are registered for implicit broadcast intents. Leaving them in place does not break your app at build-time or runtime, but they have no effect when your app runs on Android O.
Explicit broadcast intents—those that only your app can respond to—continue to work the same on Android O.
There are exceptions to this new restriction. For a list of implicit broadcasts that still work in apps targeting Android O, see Implicit Broadcast Exceptions.
Test your Android O app
With the above preparations complete, you can build your app and then test it further to make sure it works properly when targeting Android O. This is another good time to review the Core App Quality Guidelines and Best Practices for Testing.
When you build your app with the targetSdkVersion set to 26,
there are specific platform changes you should be aware of. Some of
these changes can significantly affect your app's behavior or even
break your app altogether, even if you do not implement new
features in Android O.
Table 2 provides a list of these changes with links to more information.
Table 2. Key changes that affect apps
when targetSdkVersion is set to 26.
| Change | Summary | Further reference |
|---|---|---|
| Privacy | Android O does not support use of the net.dns1, net.dns2, net.dns3, or net.dns4 system properities. | Behavior Changes: Privacy |
| Writable and Executable Segments Enforced | For native libraries, Android O enforces the rule that data shouldn’t be executable, and code shouldn’t be writable. | Behavior Changes: Native Libraries |
| ELF header and section validation | The dynamic linker checks more values in the ELF header and section headers, and fails if they are invalid. | Behavior Changes: Native Libraries |
| Notifications | Apps targeting Android O version of the SDK must implement one or more notification channels to post notifications to users. | API Overview: Notifications |
The List.sort() method
|
Implementations of this method may no longer call Collections.sort(), or your app will throw an exception due to stack overflow.
|
Behavior Changes: Collection handling |
The Collections.sort() method
|
In List implementations, Collections.sort() now throws a
ConcurrentModificationException.
|
Behavior Changes: Collection handling |
For a more extensive list of behavior changes in Android O, see Android O Behavior Changes.
To explore the new features and APIs available with Android O, see Android O Features and APIs.