Tag Archives: Android Studio

Introducing Android Instant Apps SDK 1.1

Jichao Li, Software Engineer; Shobana Ravi, Software Engineer

Since our public launch at Google I/O, we've been working hard to improve the developer experience of building instant apps. Today, we're excited to announce availability of the Android Instant Apps SDK 1.1 with some highly-requested features such as improved NDK support, configuration APKs for binary size reduction, and a new API to maintain user's context when they transition from an instant app to the installed app.

Introducing configuration APKs

For a great instant app experience, app binaries need to be lean and well structured. That's why we're introducing configuration APKs.

Configuration APKs allow developers to isolate device-specific resources and native libraries into independent APKs. For an application that uses configuration APKs, the Android Instant Apps framework will only load the resources and native libraries relevant to the user's device, thereby reducing the total size of the instant app on the device.

We currently support configuration APKs for display density, CPU architecture (ABI), and language. With these, we have seen an average reduction of 10% in the size of the binaries loaded. Actual savings for a given app depend on the number of resource files and native libraries that can be configured.

As an example, a user on an ARM device with LDPI screen density and language set to Chinese would then receive device-agnostic code and resources, and then only get the configuration APKs that have ARM native libraries, the Chinese language, and LDPI resources. They would not receive any of the other configuration APKs such as the x86 libraries, Spanish language strings, or HDPI resources.

Setting up configuration APKs for your app is a simple change to your gradle setup. Just follow the steps in our public documentation.

Persistent user context after installation

On Android Oreo, the internal storage of the instant version of the app is directly available to the installed version of the app. With this release of the SDK, we are enabling this functionality on older versions of the Android Framework, including Lollipop, Marshmallow, and Nougat devices.

To extract the internal storage of the instant app, installed apps can now call InstantAppsClient.getInstantAppData() using the Instant Apps Google Play Services API and get a ZIP file of the instant app's internal storage.

Check out our code sample and documentation for more details on how to use this API.

Start building your Android Instant App

It's simple to start building your instant app on the latest SDK. Just open the SDK Manager in Android Studio and update your Instant Apps Development SDK to 1.1.0. We can't wait to see what instant app experiences you build with these new features.

Next-generation Dex Compiler Now in Preview

Posted by James Lau, Product Manager

Android developers know that dex compilation is a key step in building an APK. This is the process of transforming .class bytecode into .dex bytecode for the Android Runtime (or Dalvik, for older versions of Android). The dex compiler mostly works under the hood in your day-to-day app development, but it directly impacts your app's build time, .dex file size, and runtime performance.

That's why we are investing in making important improvements in the dex compiler. We're excited to announce that the next-generation dex compiler, D8, is now available for preview as part of Android Studio 3.0 Beta release.

When comparing with the current DX compiler, D8 compiles faster and outputs smaller .dex files, while having the same or better app runtime performance.

* Tested with benchmark project here.
*Tested with benchmark project here.

How to try it?

D8 is available for your preview starting with Android Studio 3.0 Beta. To try it, set the following in your project's gradle.properties file:

android.enableD8=true

We have tested D8's correctness and performance on a number of apps, and the results are encouraging. We're confident enough with the results that we are switching to use D8 as the default dex compiler for building AOSP. There are currently no known issues, but we would love to hear your feedback. You can file a bug report using this link.

What's next?

We plan to preview D8 over the next several months with the Android Studio 3.0 release. During this time, we will focus on addressing any critical bug reports we receive from the community. We plan to bring D8 out of preview and enable it as the default dex compiler in Android Studio 3.1. At that time, the DX compiler will officially be put in maintenance mode. Only critical issues with DX will be fixed moving forward.

Beyond D8, we are also working on R8, which is a Proguard replacement for whole program minification and optimization. While the R8 project has already been open sourced, it has not yet been integrated with the Android Gradle plugin. We will provide more details about R8 in the near future when we are ready to preview it with the community.

Tool developers: get your bytecode tools Java 8 ready

In April, we announced Java 8 language features with desugaring. The desugaring step currently happens immediately after Java compilation (javac) and before any bytecode reading or rewriting tools are run. Over the next couple of months, the desugar step will move to a later stage in the pipeline, as part of D8. This will allow us to further reduce the overall build time and produce more optimized code. This change means that any bytecode reading or rewriting tools will run before the desugar step. If you develop .class bytecode reading or rewriting tools for Android, you will need to make sure they can handle the Java 8 bytecode format so they can continue to work properly when we move desugaring into D8.

Happy dex'ing!

Android Instant Apps is open to all developers. Start building today!

Posted by: Jonathan Karmel, Product Manager

Earlier this year, we began testing Android Instant Apps, a new way to run Android apps without requiring installation. Thanks to our incredible developer community, we received a ton of feedback that has helped us refine the end-to-end product experience.

Today, we're opening Android Instant Apps to all developers, so anyone can build and publish an instant app. There are also more than 50 new experiences available for users to try from a variety of developers, such as HotPads, Jet, the New York Times, Vimeo, and One Football. While these experiences have only been live for a short amount of time, the early data shows positive results. For example, Jet and HotPads are seeing double digit increases in purchases and leads generated.

(left to right: One Football, Dotloop, Jet, Vimeo, HotPads and The New York Times)

Feedback from our early partners has directly shaped the development tools we're making available to all of you today.

To get started building an instant app, head over to developer.android.com and download the latest preview of Android Studio 3.0 and the Android Instant Apps SDK. You'll continue to use a single codebase. Android Studio provides the tools you need to modularize your app so that features can be downloaded as needed. Every app is different, but we've seen with our early partners that with the latest tools, instant app development typically takes about 4-6 weeks.

Once you've built your app, the Play Console provides support for distributing your instant app. You just upload your instant app APKs together with your installable APK.

Instant Apps continues to ramp up on the latest Android devices in more than 40 countries. And with Android O, we've gone further, building a new, more efficient runtime sandbox for instant apps, sharable support libraries to reduce app size, and launcher integration support.

To learn more, visit g.co/InstantApps. We're also hosting a session "Introduction to Android Instant Apps" on Thursday, May 18 from 1:30-2:30 PM PT at the conference to dig deeper into the topic. You'll also be able to watch the live stream on Google I/O YouTube channel.

We are excited to see what experiences you create with Instant Apps!

Java 8 Language Features Support Update

Posted by James Lau, Product Manager

Yesterday, we released Android Studio 2.4 Preview 6. Java 8 language features are now supported by the Android build system in the javac/dx compilation path. Android Studio's Gradle plugin now desugars Java 8 class files to Java 7-compatible class files, so you can use lambdas, method references and other features of Java 8.

For those of you who tried the Jack compiler, we now support the same set of Java 8 language features but with faster build speed. You can use Java 8 language features together with tools that rely on bytecode, including Instant Run. Using libraries written with Java 8 is also supported.

We first added Java 8 desugaring in Android Studio 2.4 Preview 4. Preview 6 includes important bug fixes related to Java 8 language features support. Many of these fixes were made in response to bug reports you filed. We really appreciate your help in improving Android development tools for the community!

It's easy to try using Java 8 language features in your Android project. Just download Android Studio 2.4 Preview 6, and update your project's target and source compatibility to Java version 1.8. You can find more information in our preview documentation.

Happy lambda'ing!

Android Developer Story: Robinhood uses Android Studio to quickly build and test new features

Posted by Christopher Katsaros, Developer Marketing, Android

Robinhood allows users to buy and sell stocks commission-free* in the US. It is designed to make financial investment easy for all users, even if you’ve never traded before.

With a team of two Android developers, the company has relied on fast tools like Android Studio to build rich new features, which have helped make Robinhood the highest-rated stock brokerage app on Google Play.

Watch Robinhood's Joe Binney, VP of Product Engineering, and Dan Hill, Android Developer, talk about how Android Studio is helping them achieve strong growth on Android.


The top Android developers use Android Studio to build powerful and successful apps on Google Play; learn more about the official IDE for Android app development and get started for yourself.

Get more tips and watch other success stories in the Playbook for Developers app.

*Free trading refers to $0 commissions for Robinhood Financial self-directed individual cash or margin brokerage accounts that trade U.S. listed securities via mobile devices. SEC & FINRA regulatory fees may apply.

 How useful did you find this blogpost?

Calling all early adopters for Android Studio previews

Posted by Scott Main, Technical Writer

If you love trying out all of the newest features in Android Studio and helping us make it a better IDE, we're making it even easier to download early preview builds with a new website. Here, you can download and stay up to date on all the latest Android Studio previews and other tools announcements.



Android Studio previews give you early access to new features in all aspects of the IDE, plus early versions of other tools such as the Android Emulator and platform SDK previews. You can install multiple versions of Android Studio side-by-side, so if a bug in the preview build blocks your app development, you can keep working on the same project from the stable version.

The latest preview for Android Studio 2.4 just came out last week, and it includes new features to support development with the Android O Developer Preview. You can download and set up the O preview SDK from inside Android Studio, and then use Android O’s XML font resources and autosizing TextView in the Layout Editor.

By building your apps with the Android Studio preview, you're also helping us create a better version of Android Studio. We want to hear from you if you encounter any bugs.

Android Developer Story: LinkedIn uses Android Studio to build a performant app

Posted by Christopher Katsaros, Developer Marketing, Android


LinkedIn is the world's largest social network for professionals. LinkedIn has 10 apps on Google Play, including the flagship LinkedIn app, which provides all of the same features users find on the web, so users can do things like browse and send messages to their professional network with an improved user experience.

For LinkedIn, and other teams with a large number of developers adding code to a project, making sure that everyone pays attention to areas that affect performance is vital for the quality of their app. That's why the the LinkedIn mobile team uses Android Studio to build high quality Android apps.

Watch Pradeepta Dash, Engineering Manager for Infrastructure at LinkedIn, as well as Drew Hannay, Tech Lead for the Android Infrastructure team, talk about how Android Studio helps everyone on their team stay focused on these topics while getting new engineers quickly up and running:


The top Android developers use Android Studio to build powerful, successful apps for Google Play; you can learn more about the official IDE for Android app development, and get started for yourself.

Get more tips and watch more success stories in the Playbook for Developers app.

How useful did you find this blogpost?
        


Android Developer Story: LinkedIn uses Android Studio to build a performant app

Posted by Christopher Katsaros, Developer Marketing, Android


LinkedIn is the world's largest social network for professionals. LinkedIn has 10 apps on Google Play, including the flagship LinkedIn app, which provides all of the same features users find on the web, so users can do things like browse and send messages to their professional network with an improved user experience.

For LinkedIn, and other teams with a large number of developers adding code to a project, making sure that everyone pays attention to areas that affect performance is vital for the quality of their app. That's why the the LinkedIn mobile team uses Android Studio to build high quality Android apps.

Watch Pradeepta Dash, Engineering Manager for Infrastructure at LinkedIn, as well as Drew Hannay, Tech Lead for the Android Infrastructure team, talk about how Android Studio helps everyone on their team stay focused on these topics while getting new engineers quickly up and running:


The top Android developers use Android Studio to build powerful, successful apps for Google Play; you can learn more about the official IDE for Android app development, and get started for yourself.

Get more tips and watch more success stories in the Playbook for Developers app.

How useful did you find this blogpost?
        


Android Studio 2.3

By Jamal Eason, Product Manager, Android

Android Studio 2.3 is available to download today. The focus for this release is quality improvements across the IDE. We are grateful for all your feedback so far. We are committed to continuing to invest in making Android Studio fast & seamless for the millions of Android app developers across the world.

We are most excited about the quality improvements in Android Studio 2.3 but you will find a small set of new features in this release that integrate into each phase of your development flow. When designing your app, take advantage of the updated WebP support for your app images plus check out the updated ConstraintLayout library support and widget palette in the Layout Editor. As you are developing, Android Studio has a new App Link Assistant which helps you build and have a consolidated view of your URIs in your app. While building and deploying your app, use the updated run buttons for a more intuitive and reliable Instant Run experience. Lastly, while testing your app with the Android Emulator, you now have proper copy & paste text support.

What's new in Android Studio 2.3

For more detail about the features we added on top of the quality improvements Android Studio 2.3, check out the list of the new features below:
Build
  • Instant Run Improvements and UI Changes: As a part of our focus on quality, we have made some significant changes to Instant Run in Android Studio 2.3 to make the feature more reliable. The Run action will now always cause an application restart to reflect changes in your code that may require a restart, and the new Apply Changes action will attempt to swap the code while your app keeps running. The underlying implementation has changed significantly to improve on reliability, and we have also eliminated the startup lag for Instant Run enabled apps. Learn more.
New Instant Run Button Actions
  • Build Cache: Introduced but disabled by default in Android Studio 2.2, Build Cache is an underlying build optimization for faster builds in Android Studio. By caching exploded AARs and pre-dexed external libraries, the new build cached leads to faster clean builds. This is a user-wide build cache that is now turned on by default with Android Studio 2.3. Learn more.
Design
  • Chains and Ratios support in Constraint Layout: Android Studio 2.3 includes the stable release of ConstraintLayout With this release of ConstraintLayout, you can now chain two or more Android views bi-directionally together to form a group on one dimension. This is helpful when you want when you want to place two views close together but want to spread them across empty space. Learn more.
Constraint Layout Chains

ConstraintLayout also supports ratios, which is helpful when you want to maintain the aspect ratio of widget as the containing layout expands and contracts. Learn more about ratios. Additionally, both Chains and Ratios in ConstraintLayout can support programmatic creating with ConstraintSet APIs.

Constraint Layout Ratios

  • Layout Editor Palette: The updated widget palette in the Layout Editor allows you to search, sort and filter to find widgets for your layouts, plus gives you a preview of the widget before dragging on to the design surface. Learn more.

Layout Editor Widget Palette

  • Layout Favorites: You can now save your favorite attributes per widget in the updated Layout Editor properties panel. Simply star an attribute in the advanced panel and it will appear under the Favorites section. Learn more.

Favorites Attributes on Layout Editor Properties Panel
  • WebP Support: To help you save space in your APK, Android Studio can now generate WebP images from PNG assets in your project. The WebP lossless format is up to 25% smaller than a PNG. With Android Studio 2.3, you have a new wizard that converts PNG to lossless WebP and also allows you to inspect lossy WebP encoding as well. Right-click on any non-launcher PNG file to convert to WebP. And if you need to edit the image, you can also right-click on any WebP file in your project to convert back to PNG. Learn more.
WebP Image Conversion Wizard

  • Material Icon Wizard Update: The updated vector asset wizard supports search and filtering, plus it includes labels for each icon asset. Learn more.
Vector Asset Wizard

Develop
  • Lint Baseline: With Android Studio 2.3, you can set unresolved lint warnings as a baseline in your project. From that point forward, Lint will report only new issues. This is helpful if you have many legacy lint issues in your app, but just want to focus on fixing new issues. Learn more about Lint baseline and the new Lint checks & annotations added in this release.
Lint Baseline Support
  • App Links Assistant: Supporting Android App Links in your app is now easier with Android Studio. The new App Links Assistant allows you to easily create new intent filters for your URLs, declare your app's website association through a Digital Asset Links file, and test your Android App Links support. To access the App Link Assistant go to the following menu location: ToolsApp Link Assistant. Learn more.
App Links Assistant
  • Template Updates: By default, all templates in Android Studio 2.3 which use to contain RelativeLayout, now use ConstraintLayout. Learn more about templates and Constraint Layout. We have also added a new Bottom Navigation Activity template, which implements the Bottom Navigation Material Design guideline.

New Project Wizard Templates
  • IntelliJ Platform Update: Android Studio 2.3 includes the IntelliJ 2016.2 release, which has enhancements such as an updated inspection window and a notifications system. Learn more.
Test
  • Android Emulator Copy & Paste: Back by popular demand, we added back the Copy & Paste feature to the latest Emulator (v25.3.1). We have a shared clipboard between the Android Emulator and host operating system, which will allow you to copy text between both environments. Copy & Paste works with x86 Google API Emulator system images API Level 19 (Android 4.4 - Kitkat) and higher.

Copy & Paste support in Android Emulator

  • Android Emulator Command Line Tools: Starting with Android SDK Tools 25.3, we have moved the emulator from the SDK Tools folder into a separate emulator directory, and also deprecated and replaced the "android avd" command with a standalone avdmanager command. The previous command line parameters for emulator and "android avd" will work with the updated tools. We have also added location redirects for the emulator command. However, if you create Android Virtual Devices (AVDs) directly through the command line you should update any corresponding scripts. If you are using the Android Emulator through Android Studio 2.3, these change will not impact your workflow. Learn more.

To recap, Android Studio 2.3 includes these new features and more:

Develop
Build
Design
Test

Learn more about Android Studio 2.3 by reviewing the release notes.

Getting Started

Download
If you are using a previous version of Android Studio, you can check for updates on the Stable channel from the navigation menu (Help → Check for Update [Windows/Linux] , Android Studio → Check for Updates [OS X]). You can also download Android Studio 2.3 from the official download page. To take advantage of all the new features and improvements in Android Studio, you should also update to the Android Gradle plugin version to 2.3.0 in your current app project.
We appreciate any feedback on things you like, issues or features you would like to see. Connect with us -- the Android Studio development team -- on our Google+ page or on Twitter.

Understanding APK packaging in Android Studio 2.2

Posted by Wojtek Kaliciński, Android Developer Advocate

Android Studio 2.2 launched recently with many new and improved features. Some of the changes are easy to miss because they happened under the hood in the Android Gradle plugin, such as the newly rewritten integrated APK packaging and signing step.

APK Signature Scheme v2

With the introduction of the new APK Signature Scheme v2 in Android 7.0 Nougat, we decided to rewrite how assembling APKs works in the Android Gradle plugin. You can read all about the low-level technical details of v2 signatures in the documentation, but here's a quick tl;dr summary of the info you need as an Android app developer:

  • The cryptographic signature of the APK that is used to verify its integrity is now located immediately before the ZIP Central Directory.
  • The signature is computed and verified over the binary contents of the whole APK file, as opposed to decompressed file contents of each file in the archive in v1.
  • An APK can be signed by both v1 and v2 signatures at the same time, so it remains backwards compatible with previous Android releases.

Why introduce this change to how Android verifies APKs? Firstly, for enhanced security and extensibility of this new signing format, and secondly for performance - the new signatures take significantly less time to verify on the device (no need for costly decompression), resulting in faster app installation times.

The consequence of this new signing scheme, however, is that there are new constraints on the APK creation process. Since only uncompressed file contents were verified in v1, that allowed for quite a lot of modifications to be made after APK signing - files could be moved around or even recompressed. In fact, the zipalign tool which was part of the build process did exactly that - it was used to align ZIP entries on correct byte boundaries for improved runtime performance.

Because v2 signatures verify all bytes in the archive and not individual ZIP entries, running zipalign is no longer possible after signing. That's why compression, aligning and signing now happens in a single, integrated step of the build process.

If you have any custom tasks in your build process that involve tampering with or post-processing the APK file in any way, please make sure you disable them or you risk invalidating the v2 signature and thus making your APKs incompatible with Android 7.0 and above.

Should you choose to do signing and aligning manually (such as from the command line), we offer a new tool in the Android SDK, called apksigner, that provides both v1 and v2 APK signing and verification. Note that you need to run zipalign before running apksigner if you are using v2 signatures. Also remember the jarsigner tool from the JDK is not compatible with Android v2 signatures, so you can't use it to re-sign your APKs if you want to retain the v2 signature.

In case you want to disable adding v1 or v2 signatures when building with the Android Gradle plugin, you can add these lines to your signingConfig section in build.gradle:

v1SigningEnabled false
v2SigningEnabled false

Note: both signing schemes are enabled by default in Android Gradle plugin 2.2.

Release builds for smaller APKs

We took this opportunity when rewriting the packager to make some optimizations to the size of release APKs, resulting in faster downloads, smaller delta updates on the Play Store, and less wasted space on the device. Here are some of the changes we made:

  • Files in the archive are now sorted to minimize differences between APK builds.
  • All file timestamps and metadata are zeroed out.
  • Level 6 and level 9 compression is checked for all files in parallel and the optimal one is used, i.e. if L9 provides little benefit in terms of size, then L6 may be chosen for better performance
  • Native libraries are stored uncompressed and page aligned in the APK. This brings support for the android:extractNativeLibs="false" option from Android 6.0 Marshmallow and lets applications use less space on the device as well as generate smaller updates on the Play Store
  • Zopfli compression is not used to better support Play Store update algorithms. It is not recommended to recompress your APKs with Zopfli. Pre-optimizing individual resources such as PNG files in your projects is still fine and recommended.

These changes help make your releases as small as possible so that users can download and update your app even on a slower connection or on less capable devices. But what about debug builds?

Debug builds for installation speed

When developing apps you want to keep the iteration cycle fast - change code, build, and deploy on a connected device or emulator. Since Android Studio 2.0 we've been working to make all the steps as fast as possible. With Instant Run we're now able to update only the changed code and resources during runtime, while the new Emulator brings multi-processor support and faster ADB speeds for quicker APK transfer and installation. Build improvements can cut that time even further and in Android Studio 2.2 we're introducing incremental packaging and parallel compression for debug builds. Together with other features like selectively packaging resources for the target device density and ABI this will make your development even faster.

A word of caution: the APK files created for Instant Run or by invoking a debug build are not meant for distribution on the Play Store! They contain additional instrumentation code for Instant Run and are missing resources for device configurations other than the one that was connected when you started the build. Make sure you only distribute release versions of the APK which you can create using the Android Studio Generate Signed APK command or the assembleRelease Gradle task.