Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Including the ViewModel Dependency
Before you can write a ViewModel class, you need to include two libraries in your project.
The ViewModel class comes from an Android Jetpack library called androidx.lifecycle, one of many libraries that you will use throughout this book.
(You will learn more about Jetpack later in this chapter.)
You will also include the androidx.activity library, which adds some functionality to your MainActivity.
To include libraries in your project, you add them to the list of dependencies. Like the configuration for View Binding you did back in Chapter 2, your project’s dependencies live in the app/build.gradle file. Under Gradle Scripts in the project tool window, open the build.gradle file labeled Module: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access