Troubleshooting for Kotlin SDK

Understand what to do when you encounter the most common issues.

Android crashes with org.json classes

If your Android release build crashes immediately on startup with errors related to org.json classes, this might be caused by ProGuard configuration of your project.

Root cause

The PubNub Kotlin SDK introduces a dependency on org.json classes that are built into the Android platform. When ProGuard obfuscates your release build, it may try to rename these classes, causing runtime crashes because the Android system expects the original class names.

Fix

Add this rule to your ProGuard configuration file (proguard-rules.pro) to prevent renaming of org.json classes:

# Prevent renaming of org.json classes (required for Android)
-keepnames class org.json.** {
*;
}

Android crashes on older API versions

If your app crashes on Android API levels below 26 with java.time related errors, you need to enable Java 8 API desugaring.

Root cause

The Kotlin SDK uses java.time package features that were added in Android API 26. Apps with minSdkVersion below 26 don't have access to these APIs by default.

Fix

Enable Java 8 API desugaring in your app-level build.gradle:

android {
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
}

For more information, refer to Android's Java 8+ API desugaring documentation.

Last updated on