Google I/O 2021
Keynote
Android 12
- Biggest Design change ever
- User Safety and Privacy
- Bluetooth Permision without Location
- Widgets
- Material You Component
Android Jetpack
- Modern Android Development
- Android Studio
- Android Gradle plugin 7.0.0 and new DSL
- Arctic Fox
- Kotlin
- Kotlin Symbol Processing (2x faster than kapt)
- Jetpack
- Macrobenchmark
- DataStore
- Compose Support
- Compose
- Modern UI toolkit for Android
- Declarative
- Compatible with View System (ComposeView)
- 1.0 at July
Building Across Screens
- Slidingpane Layout
- Constraint Layout 2.1
- Wear OS
- Jetpack Libraries for Wear
- Tiles
- Health Services
- Ongoing Activity
- Curved Text
- Watch Faces
- Complications
- Remote Interactions
- Input
What's new in Android
Top 3 things to know in Modern Android Development
-
Jetpack Libraries
- Stable
- Compose (july)
- Camera X
- Hilt
- Paging 3.0
- Constraint & MotionLayout
- Security Crypto
- Fragment
- Beta
- Alpha
- Macrobenchmark
- EmojiCompat
- AppSearch
- Google Shortcuts
- Room
- WorkManager
-
Tooling
- Database Inspector
- WorkManager Inspector
- Layout Inspector
-
Kotlin
Versioning
- Alpha
- Active development
- APIs may be added, changeg, removed
- Tested and highly-functional
- Beta
- Feature stabilization
- APIs change onlin in response to critical issues or community feedback
Experimental Annotations (stable)(androidx.annotation:annotation-experimental)
- Metadata than helps tools and other developers understand your code
CameraX (stable)(androidx.camera:camera)
- Unified API surface for controlling and displaying cameras across a variety of Android OS versions and devices
- Addressing common feature request and bugs
- Exposure compensation
- Access to information about camera state and features
- Camera2 settings inter-op
- Support for the latest device and OS features
- HDR Preview
- Zoom ratio control
- Do-Not-Disturb
- Performance enhancements to provide a better experience
- Photo capture up to 15% faster
- Faster initialization (up to 25% on legacy devices)
AppSearch (alpha) (androidx.appsearch:appsearch)
- High-performance full-text search for app-local and device-wide use cases
- Full-featured versus SQL
- Prefix indexing
- Relevance ranking
- Usage scoring
- Advanced full-text search
- Fuzzy matching
- Query expansion
- Languaje support
- Includes schemas for common object types based on schemas.org
- Centralized storage on Android S+ for integrating into device-wide search
DataStore (beta) (androidx.datastore:datastore)
- Data storage solution tha provides a simple, robust alternative to SharedPreferences
- Replacement for SharedPreferences
- Fully asynchronous with Kotlin coroutines / Flow support
- Multible backing implementations
- Proto DataStore (strongly typed)
- Preference DataStore (key-value pairs)
- Plug in your own
Security Crypto (stable) (androidx.security:security-crypto)
- Safely and easily encrypt Files and SharedPreferences
Hilt (stable) (androidx.hilt:hilt)
- Simplified dependendy injection solution based on Dagger, built for Jetpack
WorkManager (stable) (androidx.work:work)
- Schedule deferrable, asynchronous tasks thant must be run reliably
- 2.5+ -> Multiple processes support
- 2.7 -> Handles Android S foreground restrictions
- WorkManager Inspector available in Android Studio Arctic Fox
Room (stable) (androidx.room:room)
- Database persistence layer designed for usability, safety and testability
- Experimental support for Kotlin Symbol Processing (200% over kapt)
- Built-in support for enums
- QueryCallback to simplify tasks like logging after execution
- ProvidedTypeConverter
ConstraintLayout (stable) (androidx.constraintlayout:constraintlayout)
- Flexible, intuitive system for positioning and animating user interfaces
- version 2.0 with MotionLayout
Fragment (stable) (androidx.fragment:fragment)
- Abstraction fo segmentin a user interface into reusable components
- Under-the-hood improvements to increase stability an reduce undocumented behavior
ActivityResult
integration
- FragmentOnAttachListener
Navitagion (alpha) (androidx.navigation:navigation)
- Fragmework for navigating between destinations within an app, now with multiple backstacks
Google Shortcuts (alpha) (androidx.core:core-google-shortcuts)
- Dynamic shortcuts for Google Assistant and other Google products
EmojiCompat (alpha) (androidx.emoji2:emoji2-views)
- All the emoji, everywere
- Included by default in AppCompat 1.4.0+
Paging 3.0 (stable) (androidx.paging.paging)
- Load and display small chunks of data to improve network and system resource consumption
- First-class support for Kotlin coroutines and Flow
- Improvements to repository and presentation layers
- Support for headers, footers, separators and loading state
Macrobenchmark (alpha) (androidx.benchmark.macro:macro)
- Accurately measure app startup and scrolling performance, both locally and in CI
- View performance profiling results directly in Android Studio
- Check for regressions in CI before they hit users
Compose integrations
- Hilt, Paging, Navigation, Activity, ViewModel, ConstraintLayout
- androidx.window
- androidx.slidingpanlayout
- androidx.wear
State of Kotlin on Android
Momentum
- Usage
- 80% Top 1000 apps
- 60% professional developers
- Kotlin on services
- Benefits
- Expressivenes
- Safety
- Interroperability
- Structured Concurrency
- Null Safety
-
10% reduction of user crashed
- Kotlin Google Developer Experts (50)s
- Gradle DSL with Android Gradle Plugin 7.0.0 (alpha)
- Kotlin Symbol Processing (beta)
- First-class Symbol Processing in Kotlin
- All Kotlin Symbols
- Faster Builds (2x)
- Rich APIs
- Rewrite Compiler (from Kotlin 1.5)
Libraries APIs
- Android KTX
- Play Core
- Maps & Places
- Rich APIs
- New libraries with Kotlin
- Compose
- Kotlin gRPC (1.0 December 2020)
- Kotlin Protobuf bindings (1.0 May 2021)
- Coroutines
- Flows
- StateFlow
- SharedFlow
- LiveData to UIs, but StateFlows
- Coroutines Debugger
- Deprecation
- Synthetics for Views -> Migrate to ViewBinding
- Parcelize: change
plugin "kotlin-parcelize"
and import import kotlinx.parcelize.Parcelize
Modern languaje features
- Operator overloaging
- Extension functions
- Named parameters
- Coroutines
- Data classes
Roadmap
- Android Studio 4.1
- Database Inspector
- Tensorflow lite models
- Native memory profiler
- Android Studio 4.2
- Project upgrade assistant
- Safe Args support
- Apply changes update
- Versioning Schema
- Artic Fox (2020.3.1)
- 2020 -> Year of Intellij Version
- 3 -> Intellij Major Version
- Studio Major Version
Design
- Jetpack Compose
- Live literals
- Preview View
- Constraint Preview
- Interactive preview
- Animated drawables
- Motion editor update
- Layout validation & inspector
- Accesible scanner
Devices
- Different Screen Sizes
- Tablets/Foldables
- WearOS
- Android TV
- Automotive OS
- General
- Device manager
- Wireless ADB
Productivity
- Test retention
- Android emulator snapshots wich can capture test state failures
- Instrumentation test
- Profiling
- WorkManager Inspector
- IDE Refactoring tool
- Migrate to Non-Transitive R Classes
- Layout Editor
- Design surface improvements
- Support for ConstraintLayout 2.1
- Accessibility Scanner
- Layout Validation
- Performance improvements
- Support for Locales
- Wear & Tablet
- Layout Inspector
- Stability and performance improvements
- Compose support
- Animated Vector Drawable
- Preview Animated Vector Drawable
ConstraintLayout 2.0
- VirtualLayout: Flow
- Performance improvements
- MotionLayout
- Build in ConstraintLayout 2.0
- Coordinate easily animations of multiple views
- Seekable, reversible animations
- Motion Editor
- Android Studio 4.0+
- Build, edit and preview animations
- Convert from ConstraintLayout in 4.1 & Artic Fox
ConstraintLayout 2.1
-
Constraints
-
Flow improvements
-
Carousel
- VirtualLayout to create Carousels
- Easily build complex effects
-
Rotation support
- Rotation paths
- Rotation gestures
-
Motion Effect
- Motion Helper.
- Apply effectos on a set of views depending on their movement
-
ViewTransitions
- Specify reusable single view transitions
- Trigger them as neede or use them with MotionEffect
-
Motion Label
- Motion helper
- Animate labels easily
- Live resize, texture
-
Foldable
- Inject fold position in your layout using a ReactiveGuide helper
- With MotionLayout, updates to the fold can be animated automatically
- MotionLayout can alse be used to model different device states (open, fold, etc) and animate the transitions between them
ConstraintLayout in Compose
- ConstraintLayout-Compose 1.0
- Same ConstraintLayout engine
- Relative positioning
- DSL/JSON
- MotionLayout
- Compose Preview
- Live Literals
- Sample Data
- Interactive Preview
- Anitation Preview
Macrobenchmark: Measuring Jank and Startup
- Metrics from the field are not enough
- Performance testing is hard
- Want local measurement
- Existing Benchmark library is limited
- Stable measurement is not easy
Introducing Macrobenchmark (androidx.benchmark.macro)
How does it work
- Setup -> Test -> Process -> Present Results
- Metrics: results.json
- Traces: iter0.trace, iter1.trace, etc…
- Studio Summary
Benchmarking With Studio
- At Android Studio Artic Fox
- activityStart
- resource loading
- view inflation
- loading icons
Tracing (androix.tracing.trace)
How we're making testing more
- Reliable
- All unit and instrumentation test run throgh a unified Android Gradle test runner, learning to more consistent results
- Scalable
- Parallel device testing streaming result to all-new Test Matrix. Integration of UTP enables functionality for more scalable testing, like Gradle Managed Devices
- Productive
- Rich test results enable by UTP, such as Emulator Snapshots for test failures, streamed back to the Test Matrix
Better experience
- Use Android Gradle Plugin to execute Android Test since Artic Fox
- Enable Run Android Instrumented Tests using Gradle
- Under the hood, is delegating to Android Test Runner
What is UTP
- A Unified Test Platform
- Extensible platform that abstracts the testing environment from feature development.
- Modular vía plugins
- Functionality is added to test execution via modular plugins, allowing features to be developed and updated independently
- Shorter release cycles
- Modular development than only needs to be implemented one way for all testing environment leads to more features, sooner
Gradle Manageg Devices
- Define virtual devices and device groups using Gradle DSL
- Device lifecycles fully managed by Android Gradle plugin (AGP)
- AGP downloads any required images and SDK components
- Caches test results and utilizes emulator snapshots for faster continuous testing
- Enable snapshots for Intrumentation Test
What's new in Jetpack Compose
Compose 1.0 at July
Actual Visual System
- Complex to mantain UI state
- XML Layout (state)
- TextView (state)
- Button (state)
- LinearLayout (state)
- Activity/Fragment (state)
- findViewById()
- label.setText()
- button.setVisibility()
- linearContainer.addView()
Declarative System
State1 -> UI1
State2 -> UI2
- You completely descrube your UI for a given state
- The framework updates your UI when the state changes

- Button
- Text
- Card
- FloatingActionButton
- TopAppBar
- MaterialTheme: colors, typography, shapes
- Row -> Horizontal LinearLayout
- Column -> Vertical LinearLayout
- Box -> FrameLayout
- ConstraintLayout
Animation System
Accesibillity
Testing
Made over Kotlin
Owl App Example
Build to Interop
Compose <-> View
Using Jetpack libraries in Compose
Jetpack Libraries
- Room
- Paging
- Coroutines/Flow
- ViewModel
- Hilt
HomeViewModel implementation
Home Screen Implementation
How to reuse a Composable
State Holders
-
ViewModel type: High level screen composables - first composable used in an Activity, Fragment or destination of Navigation graph
- For example: HomeScreen or LoginScreen
-
Regular class: Reusable composables that could be potentially used multiple times on the same screen
- For example: Carousel or ExpandableCard
ViewModel
- Benefits as state holder of a screen level composable
- Survives configuration changes
- Data can survive process death via SavedStateHandle
- Better place for state whose lifecycle matches the screen
- Built-in coroutine scope: viewModelScope
Navigation with Compose