Learn about the breaking changes introduced in the Kotlin SDK.
This guide walks you through the breaking changes introduced in the Kotlin SDK.
The Kotlin SDK is built from scratch while retaining the core functionalities of the previous Android SDK.
The way of initializing the Kotlin SDK has changed. See the following snippets for comparison:
RudderClient rudderClient = RudderClient.getInstance(
this,
WRITE_KEY,
RudderConfig.Builder()
.withDataPlaneUrl(DATA_PLANE_URL)
.withLogLevel(RudderLogger.RudderLogLevel.VERBOSE)
.build()
)
val analytics: Analytics = Analytics(
configuration = Configuration(
writeKey = BuildConfig.WRITE_KEY,
application = application,
dataPlaneUrl = BuildConfig.DATA_PLANE_URL,
logLevel = Logger.LogLevel.VERBOSE,
)
)
The Java snippet for SDK initialization is shown below:
Configuration configuration = new ConfigurationBuilder(this, "WRITE_KEY", "DATA_PLANE_URL")
.setTrackApplicationLifecycleEvents(true)
.setGzipEnabled(true)
.build();
JavaAnalytics analytics = new JavaAnalytics(configuration);
In this SDK, a RudderOption
instance was created using method chaining:
val option = RudderOption()
.putIntegration(CustomFactory.FACTORY, false)
.putIntegration("Amplitude", false)
.putExternalId("brazeExternalId", "<id>")
val traits = RudderTraits()
.put("key", "value")
// Identify event is used just for demonstration purposes.
rudderClient.identify("user 1", traits, option)
In Kotlin SDK, RudderOption
is instantiated using the constructor arguments instead of method chaining:
val option = RudderOption(
customContext = buildJsonObject {
put("key", "value")
},
integrations = buildJsonObject {
put("Amplitude", true)
put("INTERCOM", buildJsonObject {
put("lookup", "phone")
})
},
externalIds = listOf(
ExternalId(type = "brazeExternalId", id = "<id>"),
)
)
val traits = buildJsonObject {
put("key-1", "value-1")
}
// Identify event is used just for demonstration purposes.
RudderAnalyticsUtils.analytics.identify(
userId = "User1",
traits = traits,
options = option
)
The corresponding Java snippet is shown below:
Map<String, Object> customContext = new HashMap<>();
customContext.put("key", "value");
Map<String, Object> nestedIntegrations = new HashMap<>();
nestedIntegrations.put("lookup", "phone");
Map<String, Object> integrations = new HashMap<>();
integrations.put("Amplitude", true);
integrations.put("INTERCOM", nestedIntegrations);
List<ExternalId> externalIds = new ArrayList<>();
externalIds.add(new ExternalId("brazeExternalId", "<id>"));
RudderOption option = new RudderOptionBuilder()
.setIntegrations(integrations)
.setExternalId(externalIds)
.setCustomContext(customContext)
.build();
HashMap<String, Object> traits = new HashMap<>();
traits.put("name", "Alex Keener");
traits.put("email", "alex@example.com");
analytics.identify("User1", traits, option);
The following table maps the SDK configuration options available in the Android SDK to the new Kotlin SDK: