Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Jetpack: what you need to know in 2019

Android Jetpack: what you need to know in 2019

GDG Devfest Wroclaw presentation

Miłosz Lewandowski

November 15, 2019
Tweet

More Decks by Miłosz Lewandowski

Other Decks in Programming

Transcript

  1. Android Jetpack: what you need to know in 2019 Miłosz

    Lewandowski Senior Android Developer @ Miquido @plnice
  2. The evolution • Android Jetpack is the next form of

    Support Library • The last version of Support Library is 28.0.0 (released September 21, 2018) • There won’t be Support Library version that is related to API 29! (Android 10) https://youtu.be/Hyt7LR5mXLc
  3. Jetpack vs AndroidX vs other namespaces • Jetpack == AndroidX

    • All of Support Library artifacts migrated to the androidx.* namespace… • ...with the exception of Design Support Library com.android.support:design -> com.google.android.material:material • Not a part of Jetpack, hosted and maintained separately https://github.com/material-components/material-components-android
  4. AndroidX packages versioning • AndroidX packages follow strict semantic versioning

    • major.minor.micro-suffix • alpha, beta, rc releases • Separated from Android API version (contrary to Support Library) ◦ versioning (re)started with 1.0.0 • No more minApi suffixes (e.g. appcompat-v7 -> appcompat)
  5. The consequences of semantic versioning • Major or minor (major.minor.micro)

    version bumps can require some additional changes to your project or include API/behavior changes • Examine release notes before bumping AndroidX packages versions • Remember about transitive dependencies
  6. The consequences of semantic versioning • AndroidX packages are released

    independently • More frequent releases (incl. alpha, beta, rc releases) https://developer.android.com/jetpack/androidx/versions
  7. Packages, alpha, beta, rc, oh my! • There are 70

    Jetpack packages • Only stable releases are suitable for production… • ...but it’s worth to check what’s coming up (from time to time) • Early feedback matters ◦ Catch bugs before AndroidX package goes out to production ◦ Suggest API and behavior changes • How to track frequent releases of multiple packages?
  8. Android 10 and Jetpack • Contextual Notification Actions ◦ since

    core 1.2.0-alpha01, currently in beta • Notification Bubbles ◦ since core 1.2.0-alpha01, currently in beta • Dark Mode improvements ◦ recreating Activities and various fixes since appcompat 1.1.0, ◦ various fixes in core 1.2.0-alpha01 ◦ dark theme support in browser 1.2.0-alpha07 • Dark Mode (Material Components): ◦ 1.1.0-beta01 contains Material Dark Theme for all components
  9. Some stuff related to Activity/Fragments • layoutId in Activity/Fragment constructor

    ◦ since stable fragment 1.1.0 (FragmentActivity, Fragment) ◦ since stable appcompat 1.1.0 (AppCompatActivity) • FragmentContainerView ◦ since fragment 1.2.0-alpha02, currently in rc ◦ replaces usage of FrameLayout, fixes animation z-index ordering issues and window insets dispatching
  10. Power in small, but useful improvements • OnBackPressedDispatcher ◦ available

    in stable activity 1.0.0 ◦ a composable alternative to overriding onBackPressed() // MyFragment.kt val callback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { ... } } requireActivity().onBackPressedDispatcher.addCallback(this, callback)
  11. Power in small, but useful improvements • SavedStateRegistry ◦ available

    in stable savedstate 1.0.0 ◦ plugin components into the restore / saveInstanceState process // MyActivity.kt val key = "SAVED_STATE_KEY" savedStateRegistry.registerSavedStateProvider(key) { Bundle().apply { ... } } val restored = savedStateRegistry.consumeRestoredStateForKey(key)
  12. Benchmarking • BenchmarkRule ◦ available in benchmark 1.0.0-rc01 @get:Rule val

    benchmarkRule = BenchmarkRule() @UiThreadTest @Test fun simpleScroll() { benchmarkRule.measureRepeated { recyclerView.scrollBy(0, recyclerView.getLastChild().height) } } https://medium.com/androiddevelopers/fighting-regressions-with-benchmarks-in-ci-6ea9a14b5c71
  13. What I didn’t mention? • Obvious packages, under heavy development

    ◦ ViewModel ◦ Lifecycle ◦ Navigation ◦ Room ◦ WorkManager ◦ Biometric ◦ ViewPager2 ◦ ...
  14. Gradle configuration for AndroidX android.useAndroidX=true The Android plugin uses the

    appropriate AndroidX library instead of a Support Library. android.enableJetifier=true The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries.
  15. Jetifier • Jetifier goes through all the libraries and their

    transitive dependencies, even if they don’t need to be migrated • Takes 12 seconds on my medium-sized project (see https://proandroiddev.com/the-state-of-jetification-in-early-2019-plus-a-bonus- gradle-plugin-aac5854af910) • Can be a problem when running clean builds (e.g. on CI) • Most of the libraries already migrated to AndroidX: ◦ Firebase, Dagger, Glide, ButterKnife, Epoxy, LeakCanary (2.0) • Some of the libraries didn’t migrate yet: ◦ Facebook SDK • How do I know if can I drop Jetifier?
  16. Can I drop Jetifier? • https://github.com/plnice/can-i-drop-jetifier • Checks (for each

    of the modules) whether there are any dependencies using support library instead of AndroidX artifacts. ./gradlew -Pandroid.enableJetifier=false canIDropJetifier Cannot drop Jetifier due to following external dependencies: * com.facebook.android:facebook-android-sdk:5.8.0 \-- com.facebook.android:facebook-login:5.8.0 \-- com.android.support:appcompat-v7:27.0.2 or No dependencies on old artifacts! Safe to drop Jetifier.
  17. Summary • If you didn’t migrate to Jetpack yet, now’s

    the time • Be aware of Jetpack’s new versioning and implications • Check out (from time to time) alpha, beta, rc versions and the release notes • Jetpack is not only a support layer for newer AOSP features… • ...but also provides many useful features... • ...not only bigger, but also smaller ones - but still very useful! • Be aware of the Jetifier tool and drop it when you can ◦ If you use my plugin I will be happy :-)