Docs
Try Apollo Studio

1. Configure your project


In this step, you'll import the starter project and add the Apollo Kotlin SDK to it.

Clone the starter project

git clone https://github.com/apollographql/apollo-kotlin-tutorial
cd apollo-kotlin-tutorial
git checkout initial

At any time, if you want to view a completed version of the project, checkout the main branch.

Open the project in Android Studio

Android Studio will take some time to index the contents of the project. Take some time to look around. You should see 3 Fragments:

  • LaunchListFragment is the first fragment. You will display a list of launches there.
  • LaunchDetailsFragment will display details about a launch and give you the opportunity to book a seat.
  • LoginFragment will allow you to log in before booking the seat.

Now build and run the project.

Note: if you see build errors, make sure you are using JDK 11 or later.

You should see an empty app:

The initial state of the project!

Now you will add Apollo Kotlin to the project.

Get the latest version of Apollo Kotlin

You can find the latest version of Apollo Kotlin from the github releases page. It is also displayed at the top of the apollo-android repo.

This tutorial uses 3.5.0 because it is the latest version at the time of writing. Feel free to use a more recent version if one is available.

Apply the plugin

Apply the Apollo plugin in app/build.gradle.kts. There are two build.gradle.kts in the project. Make sure to use the one in the app directory this time. The Apollo plugin ID is com.apollographql.apollo3.

app/build.gradle.kts
plugins {
id("com.android.application")
// ...
id("com.apollographql.apollo3").version("3.5.0")
}

The plugin contains the compiler that will generate models from your queries when you build your project.

Configure the Apollo Gradle plugin

Configure the Apollo plugin to specify the package in which the Kotlin files will be generated. Put this at the end of app/build.gradle.kts:

app/build.gradle.kts
apollo {
packageName.set("com.example.rocketreserver")
}

Add dependencies

Now add apollo-runtime to the list of dependencies. This is the actual code that will run on the device, execute queries and parse responses.

app/build.gradle.kts
dependencies {
// ...
implementation("com.apollographql.apollo3:apollo-runtime:3.5.0")
}

Android Studio will display a yellow banner, A project sync may be necessary for the IDE to work properly. Click Sync Now.

If everything goes well, Apollo Kotlin is now added to your project. Next, you will add the GraphQL schema to the project.

Edit on GitHub
Previous
0. Introduction
Next
2. Add the GraphQL schema