JakeWharton / SdkSearch

An Android app and Chrome extension for searching the Android SDK documentation.
Apache License 2.0
2.06k stars 175 forks source link

Add kotlin serialization library to fix NoClassDefFoundError at runtime. #155

Closed runningcode closed 5 years ago

runningcode commented 5 years ago

I was getting this error at runtime startup. java.lang.NoClassDefFoundError: Failed Resolution of: lkotlinx/serialization/json/JSON;

JakeWharton commented 5 years ago

This dependency already exists in the api:dac module which api:dac:jdk-temp depends on so this change should have no effect, right?

runningcode commented 5 years ago

Yeah, I was quite confused by that, but I can consistently reproduce this error when running a clean master build on my device. It's also odd to me that the circleci build is breaking for this change on a chrome-extension task.

How can we verify that the correct platform sources and dependencies are being picked up?

This is the runtime classpath output of running ./gradlew api:dac:jdk-temp:dependencies on the master branch. The target is jvm but it doesn't seem to be picking up the jvm dependencies of :api:dac.

runtimeClasspath - Runtime classpath of compilation 'main' (target  (jvm)).
+--- project :api:dac
|    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.20
|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.20
|    +--- org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.10.0
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.20
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.20
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.20
|    |    \--- org.jetbrains:annotations:13.0
|    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.20 (*)
|    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1 (*)
|    +--- org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0
|    |    +--- org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.10.0 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.20 (*)
|    \--- com.squareup.retrofit2:retrofit:2.5.0
|         \--- com.squareup.okhttp3:okhttp:3.12.0 -> 3.12.1
|              \--- com.squareup.okio:okio:1.15.0 -> 2.1.0
|                   \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.60 -> 1.3.20 (*)
+--- com.squareup.okhttp3:okhttp:3.12.1 (*)
+--- com.squareup.okio:okio:2.1.0 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib:1.3.20 (*)
+--- com.squareup.retrofit2:retrofit:2.5.0 (*)
+--- com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2
|    +--- com.squareup.retrofit2:retrofit:2.4.0 -> 2.5.0 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0-rc-57 -> 1.3.20 (*)
|    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:0.26.1-eap13 -> 1.1.1 (*)
+--- com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.2.0
|    +--- com.squareup.retrofit2:retrofit:2.4.0 -> 2.5.0 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.0 -> 1.3.20 (*)
|    \--- org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.9.0 -> 0.10.0 (*)
\--- com.google.dagger:dagger:2.21
     \--- javax.inject:javax.inject:1
JakeWharton commented 5 years ago

org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0 is the JDK runtime which is included in that list.

Here's :frontend:android:dependencies:

+--- project :search:ui-android
|    +--- project :search:presenter
|    |    +--- project :sync
|    |    |    +--- project :api:dac
|    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.21
|    |    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1 (*)
|    |    |    |    +--- org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.10.0
|    |    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.20 -> 1.3.21
|    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.21 (*)
|    |    |    |    +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1 (*)
|    |    |    |    +--- org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.10.0
JakeWharton commented 5 years ago

The problem is that the Retrofit converter depends on 0.9.0 and in 0.10.0 the types were renamed. The :api:dac module depends on 0.10.0 but as implementation which does not force api:dac:jdk-temp to see 0.10.0, it only sees 0.9.0 from the transitive dep. That's why this fixes it.