For AI agents: this page in Markdown: https://www.pubnub.com/docs/sdks/kotlin/troubleshoot.md. Documentation index: https://www.pubnub.com/llms-full.txt.

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 (for example, java.lang.NoSuchMethodError: No virtual method e()Ljava/lang/Object; in class Lorg/json/JSONTokener;), this might be caused by ProGuard or R8 configuration of your project.

Root cause​

The PubNub Kotlin SDK introduces a transitive dependency on org.json classes that are built into the Android platform. When ProGuard or R8 shrinks your release build, it may rename org.json methods (for example, nextValue() → e()). At runtime, however, Android loads its own original version of org.json from the framework — causing NoSuchMethodError crashes because the renamed method names no longer exist.

Fix​

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

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

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:

1android {
2 compileOptions {
3 // Flag to enable support for the new language APIs
4 coreLibraryDesugaringEnabled true
5 sourceCompatibility JavaVersion.VERSION_1_8
6 targetCompatibility JavaVersion.VERSION_1_8
7 }
8}
9
10dependencies {
11 coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
12}

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

Was this page useful?

Last updated on