Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 104 ยท Getting Started

Jetpack, AndroidX and Kotlin versus Java on Android

A map of Android Jetpack (Foundation, Architecture, Behavior, UI), how AndroidX replaced the Support Libraries, how to migrate, and how Kotlin compares with Java for Android development.

Search for "Android library" and you meet two names constantly: Jetpack and AndroidX. They are not rivals. Jetpack is Google's collection of libraries, tools and guidance that make everyday Android work easier. AndroidX is the package namespace (androidx.*) those libraries live in, and the replacement for the old Support Library (android.support.*). When you add androidx.lifecycle:lifecycle-viewmodel to Gradle, you are using a Jetpack library that is published under AndroidX.

This lesson is a map of the whole toolkit with pointers to the lessons that teach each part, then a short migration guide from the Support Libraries and an honest comparison of Kotlin and Java. Nothing here needs a device, so the TryIts are plain Kotlin: a library-picker and a nullability demo that show the rules rather than the framework.

Why Jetpack exists

The platform classes ship with the OS, so they change slowly and can be old on a user's phone. Jetpack libraries ship with your app, so you can use new behavior on old devices, fix bugs without waiting for a system update and get consistent behavior. They also follow best practices (lifecycle awareness, testability) and work with Kotlin features such as coroutines and Flow. Jetpack libraries are versioned independently, with alpha, beta, rc and stable releases.

The four groups

Google groups Jetpack by purpose. The groups are a good checklist of what an app typically needs.

flowchart TD
    J["Jetpack"] --> F["Foundation<br/>AppCompat, Core KTX, Test, Multidex"]
    J --> A["Architecture<br/>ViewModel, LiveData, Room, Paging, WorkManager, DataStore, Navigation, Lifecycle, Hilt"]
    J --> B["Behavior<br/>Permissions, Notifications, Media, Download manager, Sharing, Preferences, Camera"]
    J --> U["UI<br/>Compose, Fragment, Layouts, Animation, Emoji, Palette, Wear OS, TV, Auto"]

The grouping is about intent, not packages: one product can touch several groups.

Foundation

The base that makes everything else work across versions.

  • AppCompat: backward-compatible versions of Activity, Toolbar, dialogs and theming (AppCompatActivity).
  • Android KTX: Kotlin extensions that make platform APIs idiomatic (for example sharedPreferences.edit { putString(...) }). See Kotlin on Android.
  • Multidex: support for apps with more than 65,536 methods on old Android (DEX and multidex).
  • Test: the libraries for local and instrumented tests (Instrumented tests, Compose UI testing).

Architecture

The libraries that give an app a clean structure (Architecture layers).

  • Lifecycle, ViewModel and LiveData: state that survives rotation and observers that respect the lifecycle (ViewModel, LiveData).
  • Room: the SQLite abstraction (Room basics).
  • Paging: load big lists in pages (Paging).
  • WorkManager: guaranteed background work (WorkManager).
  • DataStore: modern preferences storage (DataStore).
  • Navigation: move between destinations (Navigation Compose).
  • Data Binding and View Binding: connect XML layouts to code or data (Views and Compose).
  • Hilt: dependency injection (Hilt).

Behavior

Libraries for features that interact with the system and other apps: Permissions, Notifications (Services and notifications), Media and CameraX (Media and camera), Sharing, Preferences screens, DownloadManager, Slices and similar.

UI

Jetpack Compose (the modern declarative toolkit, see Thinking in Compose) plus the older pieces: Fragment, RecyclerView, ConstraintLayout, ViewPager2, Palette, Animation and transitions, Emoji2 and the large-screen and device families Wear OS, Android TV, Android Auto and window-size classes (Adaptive layouts).

AndroidX versus the Support Libraries

Before 2018 the compatibility code came as com.android.support:* with artifact names tied to the API level (support-v4:28.0.0). That scheme was confusing: versions were coupled to platform releases and libraries could not move independently. AndroidX replaced it:

Support Library AndroidX
Package android.support.v7.app.AppCompatActivity androidx.appcompat.app.AppCompatActivity
Versioning Tied to the API level (28.0.0 was the last) Independent per library (semantic versioning)
Updates Frozen after 28.0.0 Actively developed
Artifacts Few large ones (appcompat-v7) Many small, focused ones
New features None All new work

Most renames drop the v7 and v4 parts: android.support.design.widget.FloatingActionButton became com.google.android.material.floatingactionbutton.FloatingActionButton, and android.support.v7.widget.RecyclerView became androidx.recyclerview.widget.RecyclerView.

Migrating an old project

  1. Update to a recent Android Gradle Plugin and set compileSdk to a modern level (see Gradle for Android).
  2. In Android Studio choose Refactor, Migrate to AndroidX. It rewrites imports, XML class names and Gradle dependencies, and creates a backup.
  3. Make sure gradle.properties contains android.useAndroidX=true. Add android.enableJetifier=true only if some third-party libraries still use the old Support packages: Jetifier rewrites their bytecode at build time. Remove it as soon as every dependency is migrated, because it slows builds.
  4. Fix leftovers by searching for android.support in code and layouts, then build and run the tests.

The mapping is mechanical, which makes it a good candidate for a small script. This stand-in applies a rename table to a few source lines and flags what a tool cannot guess.

Kotlin A tiny AndroidX import migrator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

The real tool also edits XML tags, manifest entries and Proguard rules, which a one-line replacement would miss.

Choosing libraries for a new app

A starting kit for a modern app: Compose for UI, Navigation for screens, ViewModel with StateFlow for state, Room for local data, Retrofit or Ktor for the network, Hilt for injection, WorkManager for background work, DataStore for settings and Coil for images. You add them through a version catalog so versions are in one place. This picker encodes the decision as data:

Kotlin Pick Jetpack libraries from needs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

Kotlin or Java for Android?

Google calls Android development Kotlin-first: new APIs, samples and documentation (including all of Compose) target Kotlin. Java still works and a large amount of existing code uses it, and both compile to the same bytecode, so they mix freely in one project.

Topic Java Kotlin
Null safety NullPointerException at run time Nullable types (String?) checked at compile time
Boilerplate Getters, setters, equals, builders by hand data class, properties, default and named arguments
Finding views findViewById casts View Binding, or none in Compose
Async code Callbacks, AsyncTask (removed), RxJava Coroutines and Flow
Type inference Limited (var since Java 10) Throughout
Extension functions No Yes (Android KTX uses them)
Compose Not supported Required
Interoperability Calls Kotlin Calls Java

The "no need for findViewById" claim is about View Binding and Compose, not Kotlin itself (the old Kotlin synthetic imports are gone). The null-safety difference is the one that prevents most crashes.

Kotlin Null safety: the compiler finds the bug

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with readln()), it gets the next line from this box.

Strengths and honest limits of Android development

Strengths: an open ecosystem and a huge range of devices, many ways to distribute, deep system integration (intents, widgets, background services), strong tooling and one language across phone, watch, TV and car. Limits: fragmentation (many screen sizes, versions and manufacturer skins that must be tested), tighter background and storage rules with each release, a build system with a learning curve, and an emulator that is slower than a real device. Most of the "hard parts" in this track (lifecycles, permissions, configuration changes) exist because of those limits, and Jetpack exists to tame them.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is AndroidX?

    AndroidX libraries are versioned independently from the OS and live in androidx.* packages.
  2. 2. When do you still need Jetifier?

    Jetifier rewrites old Support-library bytecode in dependencies. Remove it once everything is migrated to speed up builds.
  3. 3. Which Jetpack group would WorkManager and Room belong to?

    Both help structure data and background work and sit in the Architecture group.
  4. 4. What is the main compile-time safety advantage of Kotlin over Java on Android?

    String and String? are different types, so the compiler forces you to handle null.

Summary

  • Jetpack is the toolkit; AndroidX is the namespace it ships in, replacing the frozen Support Library.
  • The four groups are Foundation, Architecture, Behavior and UI; pick libraries by need.
  • Migrate with Android Studio's refactor, android.useAndroidX=true and, only if needed, Jetifier.
  • Kotlin is the first-class language; Java still interoperates fully.
  • Fragmentation and tightening platform rules are why the tooling is so large.

Next: Resources, assets and drawables.