Missed the GamesBeat Summit excitement? Don't worry! Tune in now to catch all of the live and virtual sessions here.
At its I/O 2019 developer conference, Google announced 10 new libraries for Android Jetpack, its set of components, tools, and guidance designed to accelerate app development. The company also unveiled Jetpack Compose, a new unbundled Kotlin toolkit.
Think of Android Jetpack as the successor to Support Library, a set of components that makes it easier to leverage new Android features while maintaining backwards compatibility. When Google launched Jetpack last year at I/O 2018, Android product manager Stephanie Cuthbertson described it as “the next generation of Android APIs designed to accelerate app development.”
Last year, Google said Support Library was used by 99% of all the apps in the Play Store. Today, Cuthbertson revealed that 80% of the top 1,000 apps in the Play store are using Jetpack.
10 new Android Jetpack libraries
In March, Google announced the stable releases of Jetpack WorkManager (background processing) and Jetpack Navigation (in-app navigation). The 10 new libraries the company is announcing today are deemed ready for production, even though they’re not quite finished.
Join us in San Francisco on July 11-12, where top executives will share how they have integrated and optimized AI investments for success and avoided common pitfalls.
Seven of the libraries are in alpha:
- CameraX: Create camera-driven experiences in your application without worrying about the underlying device behavior or backwards compatibility. This API is backwards compatible to Android 5.0 (API 21) or higher, ensuring that the same code works on most devices in the market. It leverages the capabilities of camera2, but uses a simpler, use case-based approach that is lifecycle-aware. This eliminates significant boilerplate code when compared with camera2. It further enables you to access the same functionality as the native camera app on supported devices. Plus, optional extensions enable features like Portrait, Night, HDR, and Beauty.
- LiveData and Lifecycles with coroutines: Lifecycle & LiveData KTX support common one-shot asynchronous operations so you can use Kotlin coroutines that are lifecycle-aware. Offering coroutine scopes tied to lifecycles, coroutine dispatchers that are lifecycle-aware, and support for simple asynchronous chains with the new LiveData builder let you use Kotlin coroutines safely.
- Benchmark: A quick way to benchmark your app code, whether it is written in Kotlin, Java, or native code. Ensure you do not introduce any latency into your code right within your development environment in Android Studio. Easily measure database queries, view inflation, or a RecyclerView scroll. The library takes care of what is needed to provide reliable and consistent results, like handling warm-up periods, removing outliers, and locking CPU clocks.
- Security: Maximize security of an application’s data at-rest by letting this library implement security best practices for you. It provides strong security that balances encryption with performance for consumer apps like banking and chat. It also provides a maximum level of security for apps that require a hardware-backed keystore with user presence and simplifies many operations, including key generation and validation.
- ViewModel with SavedState: ViewModel provides an easy way to save your UI data in the event of a configuration change but doesn’t save your app state in the event of process death. ViewModel with SavedState lets you eliminate boilerplate code. Gain the benefits of using both ViewModel and SavedState with simple APIs to save and retrieve data right from your ViewModel.
- ViewPager2: ViewPager is now based on RecyclerView and supports vertical scrolling and RTL (Right-to-Left) layouts. It also provides a much easier way to listen for page data changes with
The remaining three libraries are in beta:
- Biometrics Prompt: Provide a consistent and safe way for your users to enter their credentials with a biometric login. This library provides a simple system prompt, giving the user a trustworthy experience.
- Enterprise: Your managed enterprise apps can send feedback back to Enterprise Mobility Management providers in the form of keyed app states. Also, you can take advantage of backwards compatibility with managed configurations.
- Android for Cars: Provide your users with a driver-optimized version of your app that will be automatically installed on the vehicle’s infotainment system in vehicles equipped with Android Automotive. This OS also lets your apps work with the Android Auto app.
Google says these APIs were shaped using feedback from Android developers. The company specifically noted its early access developer programs, user studies, and communities on Reddit, Stack Overflow, and Slack.
Google today also open-sourced an early preview of Jetpack Compose. The new unbundled toolkit is meant to simplify UI development by combining a reactive programming model with Kotlin.
Don’t try Jetpack Compose on any production projects — the toolkit is nowhere near ready. “It’s not even alpha,” Chet Haase, chief advocate for Android, told VentureBeat. But Google is going to develop Jetpack Compose in the open anyway, starting today, in hopes of getting developers to share their thoughts.
Android group product manager Karen Ng led the Jetpack Compose effort. She told VentureBeat her team wanted to solve major developer pain points, and UI is an area that Jetpack hasn’t tackled yet.
“Jetpack Compose is built with all the benefits of Kotlin,” Ng explained. “So it’s entirely interoperable with Java. It’s fully declarative, for defining UI components, including drawing and custom layouts, which is not super common. So it means that you can just describe your UI as a set of functions. And then the framework itself handles all the UI optimizations under the hood, and also automatically updates the view hierarchy, rather than having the app developer maintain that themselves. It’s compatible with all existing views. So you can mix and match our current views with what we call composable views. And then it’s designed with Material and animations right from the start.”
Google justifies Jetpack Compose by saying that developers like reactive APIs and love Kotlin. The company is thus investing in the reactive approach to declarative programming and creating a way to build UIs with Kotlin. The team is building Jetpack Compose with a few core principles:
- Build with the benefits that Kotlin brings — concise, safe, and fully interoperable with the Java programming language. Designed to drastically reduce the amount of boilerplate code you have to write, so you can focus on your app code, and help avoid entire classes of errors.
- Fully declarative for defining UI components, including drawing and creating custom layouts. Simply describe your UI as a set of composable functions, and the framework handles UI optimizations and updates to the view hierarchy under the hood.
- Provide reusable building blocks that let you build custom widgets easier, and without starting from scratch.
- Compatible with existing views so you can mix and match and adopt at your own pace with direct access to all of the Android and Jetpack APIs.
- Material Design out of the box and animations from the start, so it’s easy to create beautiful apps that are full of motion.
- Accelerate development with tools like Live Preview and apply changes.
A Jetpack Compose application is made up of composable functions that transform application data into a UI hierarchy. To create a composable function, just add the @Composable annotation to the function name. Jetpack Compose uses a custom Kotlin compiler plugin under the hood — when the underlying data changes, the composable functions can be re-invoked to generate an updated UI hierarchy.
Like Android Jetpack itself, Compose is made up of individual components that you can adopt at your own pace and that are compatible with existing views. Google is asking developers for feedback and to file bugs on AOSP.