# Upgrading to CleverTap Android SDK 9.0.0 CleverTap Android SDK 9.0.0 adds support for Android 17. It is also built Kotlin-first and stays fully compatible with Java: Java and Kotlin apps, and apps and plugins built against 8.x, keep working with the documented API. This page lists everything that can affect your code, so you can check it once when you upgrade. ## Android 17 9.0.0 supports Android 17 (API 37) ([what changes in Android 17](https://developer.android.com/about/versions/17/summary)). Your app needs nothing new to use it: the [requirements](#requirements) are the same as in 8.6.0. * **`@Variable` fields:** Do not declare them `final`. The SDK cannot update `final` fields on any Android version, and apps that target Android 17 cannot change `static final` fields at all. See [Variables](Variables.md). * **Portrait-only In-Apps on tablets (apps that target Android 17):** Apps can no longer keep a portrait lock on large screens (600dp and up), so they run in landscape when the tablet is held that way. In-Apps created for portrait only are not shown in landscape, except header, footer and Picture-in-Picture (PIP) In-Apps. If your app runs only in portrait, select both Portrait and Landscape when creating the In-App campaign. ## Requirements | | CleverTap Android SDK 9.0.0 | |---|---| | Minimum Android version | `minSdk` 23 (Android 6.0). Push Templates, Geofence and Huawei Push need the same. | | `compileSdk` | 35 or higher | | Android Gradle Plugin | 8.1.1 or higher | | Kotlin (Kotlin apps only) | 1.9 or higher | | Java | No change: the SDK is Java 8 bytecode. | | Video and audio | Media3 (`androidx.media3`) for video and audio In-Apps and App Inbox messages. ExoPlayer (`com.google.android.exoplayer2`) is no longer supported. | These module versions ship with 9.0.0: Push Templates 2.8.0, Geofence 1.5.0 and Huawei Push 1.6.0. ## Before you upgrade 1. **Add Media3** if you show video or audio In-Apps or App Inbox messages. Without it, those In-Apps are not shown and those App Inbox messages are deleted from the device. See [Migrating from ExoPlayer to Media3](EXAMPLES.md#migrating-from-exoplayer-to-androidx-media3). 2. **Update the CleverTap modules together** to the versions above. 3. **Kotlin apps:** build once and fix the null-safety errors the compiler reports, using the examples below. 4. **Tests that mock CleverTap classes:** some classes are now final, so use Mockito 5+ or the `mockito-inline` mock maker (see Behaviour changes). ## Kotlin code changes These affect Kotlin code only. Java callers and implementers are unaffected. **Unchanged.** Core calls (`pushEvent`, `onUserLogin`, `pushProfile`, ...), SAM lambdas, property syntax (`cleverTapAPI.inboxMessageCount`), qualified statics (`CleverTapAPI.getDefaultInstance(context)`, `CleverTapAPI.LogLevel.DEBUG`, `HmsConstants.HPS`, `PushConstants.FCM`), `import ...PTConstants.PT_ID` and `import ...HmsConstants.HPS`, and callback overrides written either way (except `DevicePushTokenRefreshListener` and the overrides listed under "Overrides of these parameters", below): ```kotlin override fun onDisplayUnitsLoaded(units: ArrayList?) { } // compiles override fun onDisplayUnitsLoaded(units: ArrayList) { } // also compiles ``` **`List` and `Map` parameters.** `addMultiValuesForKey`, `setMultiValuesForKey`, `removeMultiValuesForKey`, `deleteInboxMessagesForIDs`, `markReadInboxMessagesForIDs`, `pushChargedEvent`, `pushDisplayUnitElementClickedEventForID`, `pushDisplayUnitElementViewedEventForID` and `CTProductConfigController.setDefaults` take a `List` or `Map` instead of an `ArrayList` or `HashMap`, so `listOf(...)`, `mapOf(...)` and `List.of(...)` work. Code that passes an `ArrayList` or `HashMap` compiles unchanged (Java too). The SDK copies the collection, so changing it after the call has no effect. **`FetchInAppsCallback` takes a lambda.** It is now a `fun interface`, so `cleverTapAPI.fetchInApps { isSuccess -> }` compiles; `object : FetchInAppsCallback` still works. **`CleverTapAPI.DevicePushTokenRefreshListener` is now a Kotlin interface.** An override must declare both parameters nullable, as Android Studio generated them for 8.x. A lambda is unaffected: ```kotlin override fun devicePushTokenDidRefresh(token: String?, type: PushType?) { } // compiles override fun devicePushTokenDidRefresh(token: String, type: PushType) { } // 9.0: "overrides nothing" cleverTapAPI.setDevicePushTokenRefreshListener { token, type -> } // compiles ``` **Display unit metadata values are typed `Any`.** `CleverTapDisplayUnit.getMetaDataForContent` returns `HashMap` and `CleverTapDisplayUnitContent.getMetaData` returns `HashMap?`; neither map contains `null` values. An inferred type compiles unchanged; a variable declared as `HashMap` must change: ```kotlin val meta = unit.getMetaDataForContent(0) // compiles val meta: HashMap = unit.getMetaDataForContent(0) // 9.0: declare HashMap ``` **Getters that can return `null` are now typed `T?`.** Add `?.`, `?:` or a null check: ```kotlin // 8.x val id: String = cleverTapAPI.cleverTapID val title: String = inboxMessage.inboxMessageContents[0].title // 9.0 val id = cleverTapAPI.cleverTapID ?: "" val title = inboxMessage.inboxMessageContents.firstOrNull()?.title.orEmpty() // 8.x val config = CleverTapInstanceConfig.createInstance(context, "ACCOUNT_ID", "ACCOUNT_TOKEN") config.setDebugLevel(CleverTapAPI.LogLevel.DEBUG) // 9.0: null only when accountId or accountToken is null val config = CleverTapInstanceConfig.createInstance(context, "ACCOUNT_ID", "ACCOUNT_TOKEN") ?: return config.setDebugLevel(CleverTapAPI.LogLevel.DEBUG) ``` This applies, for example, to `cleverTapID`, `CleverTapInstanceConfig.createInstance`, `getDefaultInstance(context, accountId)` and `instanceWithConfig`, `getProperty` and `getProfile`, `getDevicePushToken`, `getInboxMessageForId` and the inbox and display unit model getters (`CTInboxMessage.title`, `CTInboxMessageContent.message`, `CleverTapDisplayUnit.contents`, ...), `defineVariable`, `defineFileVariable` and `getVariable`, `productConfig()` and `featureFlag()`, `CTFeatureFlagsController.get`, `CTProductConfigController.getBoolean`/`getDouble`/`getLong`, `Var.stringValue()`, `numberValue()` and `kind()`, and the `UTMDetail` getters. The compiler reports each place. For a file variable, `value()` is `null` until the file is downloaded, so read it as `String?`. **Overrides of these parameters must be declared `T?`**, because the SDK does pass `null`: ```kotlin // 8.x override fun onLocationUpdates(location: Location) { } // 9.0 override fun onLocationUpdates(location: Location?) { } ``` The others are the `applicationContext` and `pushType` of `NotificationHandler.onMessageReceived`, and `processPushAmp` (see Behaviour changes). **Static imports** of `CleverTapAPI`, `CleverTapInstanceConfig`, `Logger` and other companion members need `.Companion` (`import com.clevertap.android.sdk.CleverTapAPI.Companion.getDefaultInstance`); qualified calls such as `CleverTapAPI.getDefaultInstance(context)` are unchanged. ## Behaviour changes The SDK is now written in Kotlin. Java callers and the binary API are unaffected, except for the SDK-internal classes below and these calls that pass an explicit `null`: * About 80 classes that were public only by accident are now SDK-internal, for example `AnalyticsManager`, `CallbackManager`, `DeviceInfo`, `InAppFCManager`, `LoginController`, `CTInboxController`, `CTProductConfigConstants`, `CTFeatureFlagConstants` and `LoginConstants`. They were never part of the documented API. Kotlin code can no longer use them, and Java code that does gets a lint `RestrictedApi` error. A few of them (`SCDomainListener`, `NotificationRenderedListener`, `MainThreadExecutor`, `CTWorkManagerAccessor` and the HMS `IHmsMessageHandler`) stay JVM-public with `@RestrictTo`: Kotlin code that uses them still compiles, but lint reports `RestrictedApi`. `com.clevertap.android.sdk.Utils` (its constructor is now private) and `task.Task` (its protected fields are now private) are narrowed too. Some members also changed shape: an app built against 8.x that reads `CTProductConfigConstants.DEFAULT_VALUE_FOR_BOOLEAN` now fails with `NoSuchFieldError`, and `BaseCallbackManager._notifyInboxMessagesDidUpdate()` (public abstract in 8.6.0) was removed, so code compiled against 8.x that calls it fails with `NoSuchMethodError`. Anything that is not in the public API ([clevertap-core.api](../clevertap-core/api/clevertap-core.api)) is SDK-internal. * Undocumented SDK internals are no longer public API. Kotlin and Java apps that used them get compile errors, or `NoSuchMethodError` when code built against 8.x runs (constants still link, as they are inlined): * `CleverTapAPI`: `isDevelopmentMode`, `NOTIFICATION_TAG`, and `messageDidClick`/`messageDidShow` (`CleverTapAPI` no longer implements `CTInboxActivity.InboxActivityListener`). * `CleverTapInstanceConfig`: `isBeta`, `isDefaultInstance`, `isCreatedPostAppLaunch`, `KEY_ENCRYPTION_LEVEL`, and the protected statics `createDefaultInstance` and `createInstance(String)`. * `CTInAppNotification`: the caps, TTL and layout getters (`maxPerSession`, `totalDailyCount`, `totalLifetimeCount`, `isExcludeFromCaps`, `timeToLive`, `isLocalInApp`, `fallBackToNotificationSettings`, `isRequestForPushPermission`, `swipeToDismiss`, `isPortrait`, `isLandscape`, `landscapeImageUrl`), `HTML_DEFAULT_ASPECT_RATIO` and `defaultTtl()`. * Model and helper internals: `CTInAppType.fromString`, `InAppActionType`, `db.Table`, `PushType.toJSONObject`/`fromJSONObject`/ `getTokenPrefKey`/`getCtProviderClassName`/`getMessagingSDKClassName` (its constructor and `getType` stay), `CTDisplayUnitType.type`, `CTInboxMessageContent.setPosterUrl`, the `CTLocalInApp` `Builder1`–`Builder6` constructors and its `IS_LOCAL_INAPP`/`FALLBACK_TO_NOTIFICATION_SETTINGS` keys, `Var.update`/ `triggerFileIsReady`, `CustomTemplateContext.getArgumentValues`/`getLogger`, the `ActivityLifecycleCallback` constructor and the `video.VideoLibraryIntegrated` enum. * The SDK callbacks of the deprecated controllers: `CTFeatureFlagsController.updateFeatureFlags`, `setGuidAndInit`, `resetWithGuid`, `getGuid`, and `CTProductConfigController.onFetchSuccess`, `onFetchFailed`, `setArpValue`, `resetSettings`, `setGuidAndInit`. Members that CleverTap's own SDKs and wrappers call stay JVM-public but are marked `@RestrictTo` (lint `RestrictedApi` only): `CleverTapAPI.pushSignedCallEvent`, the geofence event methods and `setLocationForGeofences`, `CleverTapDisplayUnit.toDisplayUnit`, `PushNotificationHandler.isForPushTemplates`/`onActionButtonClick`, `VariableCallback.setVariable`, `CTFirebaseMessagingReceiver.onNotificationRendered`, `HttpBitmapLoader.HttpBitmapOperation` and `DownloadedBitmap.Status`. The same applies to `CleverTapAPI.getGeofenceCallback`/`setGeofenceCallback` and `isInboxFetchDisabledForSession`, and `CleverTapInstanceConfig.isBackgroundSync`: Java still compiles and runs them (lint `RestrictedApi`), but Kotlin can no longer use them as properties (`geofenceCallback`, `isBackgroundSync`); call the functions. `CleverTapAPI.setLibrary`, `isAppForeground`, `setAppForeground`, `pushError` and `ActivityLifecycleCallback.registered` stay public API: integration partners outside CleverTap (Segment, Rudder, Leanplum) call them. * These classes are now final, and so are their methods: `CleverTapAPI`, `CleverTapInstanceConfig`, `CTInboxMessage`, `CTInboxMessageContent`, `CTInboxStyleConfig`, `CleverTapDisplayUnit`, `CleverTapDisplayUnitContent`, `Var`, `PushType`, `PushNotificationHandler`, `UTMDetail`, `EventDetail`, `CTWebInterface`, the deprecated `CTFeatureFlagsController`, `CTProductConfigController` and `ProductConfigSettings`, and the Geofence SDK's `CTGeofenceAPI` and `CTGeofenceSettings` (the protected `Parcel` constructors of `CTInboxStyleConfig` and `CTInboxMessageContent` are now private). Nothing changes at runtime; tests that mock them need Mockito 5+ or the `mockito-inline` mock maker. The [Push Templates](CTPUSHTEMPLATESCHANGELOG.md), [Geofence](CTGEOFENCECHANGELOG.md) and [Huawei Push](CTHUAWEIPUSHCHANGELOG.md) changelogs list their module changes. * `CleverTapAPI.parseVariables((Object[]) null)` and `parseVariablesForClasses((Class[]) null)` now throw a `NullPointerException` (it was logged and ignored before). Passing classes or instances, including null elements, is unaffected. * `CleverTapAPI.getUserEventLog(null)` and `getUserEventLogCount(null)` now throw `IllegalStateException` instead of `NullPointerException`. * From Java, `CleverTapInstanceConfig.setIdentityKeys((String[]) null)`, `new PushType(...)` with a `null` `type` or `prefKey`, and `Var.addFileReadyHandler(null)` now throw a `NullPointerException`. * Kotlin subclasses of `CTFcmMessageHandler` or `CTHmsMessageHandler` that override `processPushAmp(context, message)` must declare `message` nullable (`RemoteMessage?`); a null message is ignored (FCM) or logged (HMS), as in earlier versions. Java subclasses are unaffected. * A custom `CTPushProvider` that calls `onNewToken(token, null)` no longer reaches the app's `DevicePushTokenRefreshListener` (8.x called it with a `null` type). Pass the provider's push type. FCM and HMS are unaffected. * `CleverTapAPI.getInstances()` now returns a copy of the registered instances and never returns `null` (an empty map before the first instance). Changing the returned map, for example with `clear()`, `remove()` or `put()`, no longer changes the SDK's own list of instances.