Breaking Changes in Android (Kotlin) SDK 2.0.0
5 minute read
This guide lists the breaking changes in the Android (Kotlin) SDK 2.0.0 and the device mode integrations released with it. Review them before you upgrade from an Android (Kotlin) SDK 1.x version.
Overview
Android (Kotlin) SDK 2.0.0 has the following breaking changes:
- The SDK starts automatic sessions and sends
Application InstalledorApplication Updatedwhen the user first opens the app. Before 2.0.0, it did this when it initialized. - By default, background events no longer carry
sessionIdorsessionStart. - One session configuration parameter has a new name.
- All device mode integrations have a new major version that requires SDK 2.0.0.
- The CleverTap integration requires a newer CleverTap Android SDK and a higher
minSdk.
Upgrade the SDK and integrations together
The device mode integrations released with SDK 2.0.0 require SDK 2.0.0 or later. Upgrade the SDK and all integrations in the same app release:
| Package | Version |
|---|---|
com.rudderstack.sdk.kotlin:android | 2.0.0 |
com.rudderstack.integration.kotlin:adjust | 2.0.0 |
com.rudderstack.integration.kotlin:appsflyer | 3.0.0 |
com.rudderstack.integration.kotlin:braze | 2.0.0 |
com.rudderstack.integration.kotlin:clevertap | 2.0.0 |
com.rudderstack.integration.kotlin:facebook | 2.0.0 |
com.rudderstack.integration.kotlin:firebase | 2.0.0 |
com.rudderstack.integration.kotlin:sprig | 2.0.0 |
Session tracking
A background event is an event that your app sends while it has no visible screen. Events sent from Application.onCreate before the first screen opens are also background events. A foreground service, for example in a music player, sends background events too.
Parameter renamed
The updateSessionOnBackgroundEvents parameter of SessionConfiguration is now includeBackgroundEventsInSession. The old name no longer exists. Code that uses it does not compile. The default value stays false. Its behavior also changes, as the next sections describe.
// 1.7.0 to 1.8.0
SessionConfiguration(updateSessionOnBackgroundEvents = true)
// 2.0.0 and later
SessionConfiguration(includeBackgroundEventsInSession = true)// 1.7.0 to 1.8.0
new SessionConfigurationBuilder().setUpdateSessionOnBackgroundEvents(true).build();
// 2.0.0 and later
new SessionConfigurationBuilder().setIncludeBackgroundEventsInSession(true).build();Sessions start when the user opens the app
| Before 2.0.0 | 2.0.0 and later |
|---|---|
| The SDK starts or continues a session when it initializes. This also happens when Android starts the app in the background, for example to deliver a push notification. | When the user first opens the app, the SDK continues the stored session. If no session exists or the stored one timed out, the SDK starts a new one. |
Impact: WhenincludeBackgroundEventsInSessionisfalse, a background app start no longer creates a session. Your session count can decrease after the upgrade.
Background events when includeBackgroundEventsInSession is false (default)
| Before 2.0.0 | 2.0.0 and later |
|---|---|
Background events carry sessionId. They do not extend the session after the user leaves the app. In an app that Android starts in the background, they can extend it. | Background events do not carry sessionId or sessionStart, and they do not extend the session. |
analytics.sessionId returns the stored session ID in the background. | analytics.sessionId returns null in the background. |
These rules apply to automatic sessions. In a manual session, background events carry sessionId as before.
The SDK’s lifecycle events (Application Installed, Application Updated, Application Opened, and Application Backgrounded) carry sessionId in the background. They do not extend the session. The SDK matches these events by name. A track event from your app with one of these names also carries sessionId.
Action: If your app tracks user activity from the background or from a foreground service, setincludeBackgroundEventsInSessiontotrue.
Background events when includeBackgroundEventsInSession is true
| Before 2.0.0 | 2.0.0 and later |
|---|---|
| A background event after the session timeout continues the old session. | A background event after the session timeout starts a new session. |
From 2.0.0, a background event also starts a new session when no session exists. For example, your app can send an event when a push notification arrives. If the user has not opened the app yet, that event starts a session. When the user opens the app within the timeout, the same session continues.
sessionStart can be on any event
The SDK sets context.sessionStart on the first event that carries the ID of a new session. Before 2.0.0, this was usually Application Installed or Application Opened. From 2.0.0, this is more often an app event, for example a background event that starts a session.
Action: Some reports or transformations find new sessions bysessionStarton one event name. Change them to readsessionStarton any event.
See Session Tracking in Mobile SDKs for the full session rules.
Lifecycle events
| Before 2.0.0 | 2.0.0 and later |
|---|---|
The SDK sends Application Installed or Application Updated when it initializes. This also happens when Android starts the app in the background. | The SDK sends Application Installed or Application Updated when the user first opens the app. |
If a user installs your app and never opens it, the SDK does not send Application Installed. If Android starts the app in the background first, the SDK sends the event later, when the user opens the app.
See Application Lifecycle Tracking in Mobile SDKs for more information.
CleverTap integration
The CleverTap integration 2.0.0 has the following breaking changes:
| Change | Before 2.0.0 | 2.0.0 and later |
|---|---|---|
| CleverTap Android SDK version | [7.3.1, 7.7.0) | [8.4.1, 9.0.0) |
minSdk | 21 | 23 |
| Activity tracking | The integration forwards the activity callbacks to CleverTap. | The integration calls CleverTap’s ActivityLifecycleCallback.register. CleverTap tracks app launches, notification clicks, deep links, and in-app messages itself. |
Note the following:
- If your app declares an older CleverTap Android SDK version, Gradle replaces it with the newest version in the range
[8.4.1, 9.0.0). - If your app pins an older version with
strictly, the build fails. Do not force an older version withforce. - If your app calls the CleverTap SDK directly, review the CleverTap Android SDK changelog for the changes up to your new version.
- If your app creates the CleverTap instance itself before RudderStack initializes the destination, for example by calling
ActivityLifecycleCallback.registerorCleverTapAPI.getDefaultInstance, add your CleverTap credentials to the manifest. Without them, RudderStack cannot create the CleverTap destination.
See CleverTap for the setup steps.
Upgrade checklist
- Upgrade the SDK and all device mode integrations to the versions in Upgrade the SDK and integrations together.
- In Kotlin, rename
updateSessionOnBackgroundEventstoincludeBackgroundEventsInSession. In Java, renamesetUpdateSessionOnBackgroundEventstosetIncludeBackgroundEventsInSession. - Set
includeBackgroundEventsInSessiontotrueif your app tracks user activity from the background or from a foreground service. - Review reports and transformations that count sessions, use
sessionStart, or expectsessionIdon background events. - If you use the CleverTap integration, set
minSdkto 23 or higher. Then read the notes in CleverTap integration.