Android O Preview: What Developers Need to Know

The Android O SDK (API 26) dropped recently and the internet went nuts! The Developer Preview SDKs brought along many new features. But these new SDKs are the pre-final ones.

It’s that time of the year when Android Developers like you and me need to keep up with what’s latest.

I usually refrain from writing about Developer Previews, until a stable release arrives. But it’s better we get to know what’s new now. Rather than coping with changes in the future. So transitioning our apps to Android O will be smooth when the time comes.

Trying Android O with Android Studio EAP

Android Studio EAP (Canary Channel) Credits: tools.android.com

In this post, we’ll first see how to setup Android Studio Preview. We need this to try out the new Android O Developer Preview SDKs.

Google I/O 2017 released Android Studio 3.0. They also released Android O RC2. Hence this updated article will be using them. But don’t worry as I’ll walk you through that as well. We’ll install Android Studio EAP in parallel to your existing Android Studio. So nothing will get affected.

Next, we’ll install the Android O Preview SDKs. This includes the Preview SDKs itself, Support Libraries and a System Image.

Android O release schedule. Credits: developer.android.com

As you can see from the release schedule. We no longer have to use the preview SDKs. The beta SDKs for API 26 (Android O) has been released. We will be using that from now on.

Before setting up everything, let’s see what Android O has to offer.


Some of the biggest features in Android O are:

1. Picture-in-Picture (PIP) support for Android Mobile

PIP was first introduced in Android Nougat. It became famous by the floating video player in YouTube. Just add the attribute android:supportsPictureInPicture attribute in your tag in AndroidManifest.xml.

But, back then it was limited to Android TV. With Android O, they’ve finally brought it to smartphones as well. Goodbye DraggablePanel?

PIP in YouTube app

Learn how to use Picture-in-Picture in this Android O tutorial.

2. Custom Font support

No need to use a library or write a custom View. Drop in your fonts to res/fonts folder. Then you can use them with a single attribute.

android:fontFamily="@font/Merriweather"

Finally we can start seeing apps with less of Roboto!

You can read the full tutorial on how to use custom font resources.

3. Autofill Framework

Users can save time filling out forms by using autofill in their devices

Long story short. Are you familiar with auto-filling forms in your web browsers? Remembering your passwords and credit card information to autofill it when required. That’s available on Android now. Sweet?

4. Notification Channels

Notifications are great. Every Android release made it better. But honestly, notifications are a spam-fest on our phones right now.

Notification Channels provide a unified system to help users manage notifications

In short, Notification Channels let you group your notification into broad categories. You can change the behavior of these broad notification categories in your settings.

Other little, but noteworthy changes

Adaptive Icons

Adaptive icons can help you integrate better with device UI, which can display a variety of shapes across different device models.

Honestly, I don’t get the point of this feature. It started with Nougat wanting to make every icon round. But now this.

Credits to android-developers.googleblog.com

ProgressDialog deprecated
Developer docs suggest a good UX tip. To use an inline ProgressBar in an Activity, instead of this modal dialog. But, you can take it a step further by using a better Progress Indicator called Skeleton Screen.

Text Justification
Spreads the typography over the full width. You just need one line and you’re good to go.

textView.setJustify(true);

Directional Attributes
No more padding top, bottom, left and right. Just paddingHorizontal and paddingVertical. Save yourself from writing two extra lines.

Credits to Cryil Mottier for this

OpenJDK Features for Android O
Some of the newly added packages include java.time and java.nio.file. You can read the complete Android O API differences report here.

Smart Sharing
Android O learns your preference and suggests relevant apps depending on what you’re sharing. For example, if you want to share a photo, Android might suggest social media apps.

Now we’re fully aware of what Android O has to offer. Time for us Android Developers to start preparing our apps for Android O.


How to Develop for Android O right now?

To access the preview, you must first download to Android Studio 3.0 Preview.

A word of caution:
Keep in mind, we’re using an unstable IDE. So make sure to update your SDKs and IDE as soon as an update is available.

The official Android developer documentation explains how to setup Android O. I highly recommend you follow their guide first. You can safely install Android Studio Preview in parallel to your existing, stable Android Studio.

In short, nothing gets affected. Android Studio Preview will safely use your existing SDK path.

NOTE:
As of now, you must use Android Studio preview. Otherwise many of the new features simply will not work!

Android O SDK Download

Open SDK Manager and download the Android O SDK (API 26). Notice that these are the almost-final SDKs that you can expect in production.

In other words, these include API changes that will carry forward from now on.

Android O DP2 Install Checklist

But just in case, here’s a quick checklist of everything you need to do:

  1. Download and install Android Studio 3.0 Preview
  2. Next, install Android 7+ (O) – SDK Platform 26
  3. Download a preview image for emulator (Google Play Intel x86 Atom System Image). This includes Google Play Services
  4. Download and install SDK Build-Tools 26
  5. Update your SDK Tools(26.0.2) and SDK Platform-Tools (26.0.0)
  6. Create a new project targeting Android O Preview
  7. Check app/build.gradle if correct targetSdkVersion and Support libraries are used
  8. Create a new AVD targeting Android O
  9. Test your app by running it on the new AVD

The setup might look exhausting. But trust me, it took hardly an hour to do all that.

Once you’re done with all that, you’ll need to update your Gradle plugin as well. So first, replace the distributionUrl in your gradle-wrapper.properties file.

distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-rc-1-all.zip

This gives you the latest Gradle version that you need to be using for API 26. Otherwise your project will fail to compile.

Finally, cross-check your app/build.gradle file with mine.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.iamsuleiman.androido"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    // To take advantage of cool Java 8 features, like Lambdas!
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

ext {
    supportLibVersion = "26.0.0-beta2"
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    ...
    compile "com.android.support:appcompat-v7:${supportLibVersion}"
    compile "com.android.support:design:${supportLibVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibVersion}"
    ...
}

If you’re gradle file is looking like this, then you’re all set to play with Android O.

Moreover, developer.android.com does a good job of walking you through. It is fairly simple. But, if you get stuck anywhere, feel free to drop a comment here or send me a Tweet. I’ll be happy to help.


What’s next?

With Android Studio 3.0 Preview setup, and the new SDKs downloaded, you’re good to go. You can compile and test your apps against Android O and check if everything works smoothly.

Also, you can use this time to make your apps take advantages of the new features. For example, expect the Autofill Framework and Notification Channels to be widely used. Even if you don’t want to support Android O right now, it’s okay. You can test drive the new SDKs and see what it has to offer.

So what did you like about Android O? Did you notice the new changes from the previous release? My particular favourite is downloadable custom fonts.

What’s your favourite feature? Did I miss anything? Tell me in the comments below.

Suleiman

Product Designer who occasionally writes code.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *