Android Setup
Installation
The Rover SDK is a collection of Android libraries written in Kotlin. Instead of a single monolithic library, the Rover SDK takes a modular approach, allowing you to include only the functionality relevant to your application. The SDK source code is available on GitHub.
Install the SDK
The first step is to add the library dependencies. We’ll start with a default installation, featuring all of the Rover libraries.
Ensure that you have Rover's maven repository added to the dependencies
→ repositories
block of your app-level build.gradle
:
dependencies {
// ...
repositories {
// ...
maven {
url "https://roverplatform.github.io/rover-maven/maven"
}
}
}
Then add the following to your application-level build.gradle
file (not the top level build.gradle
, but rather your app-level one) in the dependencies
block, replacing 4.9.0
with the latest version available of the Rover SDK.
dependencies {
// ...
implementation "io.rover.sdk:core:4.9.0"
implementation "io.rover.sdk:notifications:4.9.0"
implementation "io.rover.sdk:experiences:4.9.0"
implementation "io.rover.sdk:location:4.9.0"
implementation "io.rover.sdk:debug:4.9.0"
}
Latest SDK Version
Look at the GitHub releases pages for the changelog of available versions, and when initially integrating be sure to replace 4.9.0
with the latest (or your preferred) version.
It’s an a-la-carte selection; you can leave off modules (other than the first, core
, which is always required) that you don’t need for your product. There are various reasons why you may not want to include all the Rover libraries in your project. For instance, you can save method count and APK size by leaving off Rover libraries that you don't need.
Initialization
In your app’s Application.onCreate method or anywhere else you prefer to put initialization logic (such as a dependency injection framework), call Rover.initialize
with the list of Assemblers:
Rover.initialize(
CoreAssembler(
accountToken = "YOUR_SDK_TOKEN",
application = this,
urlSchemes = listOf("rv-myapp"),
associatedDomains = listOf("myapp.rover.io")
),
ExperiencesAssembler(),
NotificationsAssembler(
applicationContext = this,
notificationCenterIntent = Intent(context, MyNotificationCenterActivity::class.java),
smallIconResId = R.mipmap.my_small_icon,
requestPushToken = { tokenCallback ->
// this will be discussed later on the "Push Notifications" page.
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (task.isSuccessful) tokenCallback(task.result)
}
}
),
LocationAssembler(),
DebugAssembler()
)
Rover.installSaneGlobalHttpCache(application)
Initialization Order
In larger, more complex apps, it is common for the initialization logic for SDKs like Rover within some larger pattern for composing initialiation. However, wherever you may put the Rover initialization logic, you need to be certain that Rover is initialized before Android can dispatch an Intent to the app, such as a push notification or deep link open. Deferred SDK startup regimes may cause compatibility problems with Rover.
Don’t sweat the parameters for now; they’re in each section of the documentation for each module.
Add the Experience Activity to Manifest
Rover's Experiences feature is typically used in an Activity, and one is bundled with the SDK. Add an entry for it to your manifest:
<activity
android:name="io.rover.sdk.experiences.ExperienceActivity"
android:exported="true"
/>
ExperienceActivity Color Theming
Classic Experiences feature the ability to adopt the color scheme of your app for the app bar, using the "Auto-Style" setting. This means you'll need to give the SDK some information about your theme in order for it to adopt it.
You can either use classic Android color values (such as you might resolve from your theme resource XML files), or you might use your Jetpack Compose theme colors.
Provide the appThemeDescription
parameter to the ExperienceAssembler()
in your Rover initialization lines.
Using Classic Android Color Values
Create a new AppThemeDescription.ThemeColors
object with android numeric color values resolved from your theme like this, and provide it to ExperiencesAssembler:
Rover.initialize(
...,
ExperienceAssembler(
appThemeDescription = AppThemeDescription(
lightColors = AppThemeDescription.ThemeColors(
// get your colors from your theme resources like this:
primary = this.resources.getColor(R.color.colorPrimary, null),
onPrimary = this.resources.getColor(R.color.colorAccent, null)
),
darkColors = AppThemeDescription.ThemeColors(
// get your colors from your theme resources like this:
primary = this.resources.getColor(R.color.colorPrimaryDark, null),
onPrimary = this.resources.getColor(R.color.colorAccent, null)
)
)
)
Using Jetpack Compose Colors
Create a new AppThemeDescription.ThemeColors
object with your Jetpack Compose Colors values (as are likely present in your Theme.kt
file generated by Android Studio), and provide it to ExperiencesAssembler:
Rover.initialize(
...,
ExperienceAssembler(
appThemeDescription = AppThemeDescription(
lightColors = AppThemeDescription.ThemeColors(LightColorPalette),
darkColors = AppThemeDescription.ThemeColors(DarkColorPalette)
)
)
)