Learn about the breaking changes introduced in the Android (Kotlin) SDK.
The Android (Kotlin) SDK is built from scratch while retaining the core functionalities of the legacy Android (Java) SDKAndroid (Java) refers to the legacy RudderStack Android SDK. Note that it will be deprecated soon.
For new implementations, use the Android (Kotlin) SDK instead.
.
The way of initializing the Android (Kotlin) SDK has changed. See the following snippets for comparison:
RudderClient rudderClient = RudderClient.getInstance(
this,
WRITE_KEY,
RudderConfig.Builder()
.withDataPlaneUrl(DATA_PLANE_URL)
.build()
)
val analytics: Analytics = Analytics(
configuration = Configuration(
writeKey = BuildConfig.WRITE_KEY,
application = application,
dataPlaneUrl = BuildConfig.DATA_PLANE_URL,
)
)
The Java snippet for SDK initialization is shown below:
Configuration configuration = new ConfigurationBuilder(this, "WRITE_KEY", "DATA_PLANE_URL")
.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 Android (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);
This section covers the different feature updates introduced in the Android (Kotlin) SDK: