Store icon indicating copy to clipboard operation
Store copied to clipboard

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/atomicfu/AtomicFU

Open sridharshanmugam opened this issue 3 years ago • 11 comments

When migrating from Store4 to Store5, the below-mentioned crash happened in the Android platform.

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/atomicfu/AtomicFU;
        at org.mobilenativefoundation.store.store5.impl.SourceOfTruthWithBarrier.<init>(SourceOfTruthWithBarrier.kt:57)
        at org.mobilenativefoundation.store.store5.impl.RealStore.<init>(RealStore.kt:56)
        at org.mobilenativefoundation.store.store5.impl.RealStoreBuilder.build(RealStoreBuilder.kt:38)
Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlinx.atomicfu.AtomicFU" on path

In the latest Store5, since the Kotlin version 1.7.21 is used, I have updated the Compose Compiler Version to 1.4.0-alpha02. But in the AtomicFU, they have mentioned turning on IR transformation by setting the below-mentioned properties in the gradle.properties file for Kotlin version >= 1.7.20.

kotlinx.atomicfu.enableJvmIrTransformation=true // for JVM IR transformation
kotlinx.atomicfu.enableJsIrTransformation=true // for JS IR transformation

But in the Store5 gradle.properties file, it was configured as mentioned below for the AtomicFU version 0.18.5.

kotlinx.atomicfu.enableJvmIrTransformation=false
kotlinx.atomicfu.enableJsIrTransformation=false
kotlin.js.compiler=ir

I'm not sure whether this might be the reason for the above-mentioned crash in the Android platform.

sridharshanmugam avatar Dec 23 '22 12:12 sridharshanmugam

Hello! First off just a warning store5 is not stable yet. You are free to play with it but we do not recommend prod usage yet.

As for the error. Could you try adding this dependency to modules uses store https://search.maven.org/artifact/org.jetbrains.kotlinx/atomicfu/0.18.5/pom

digitalbuddha avatar Dec 23 '22 12:12 digitalbuddha

I have tried adding the AtomicFU dependency in the Android project and checked with Kotlin versions 1.7.20 (used in the AtomicFU) and 1.7.21, but still, the same crash occurred in the Android.

sridharshanmugam avatar Dec 23 '22 13:12 sridharshanmugam

hmm strange, I have. KMP project where I was able to successfully add Store5 and compile the android app. https://github.com/AndroidDev-social/DodoForMastodon/blob/main/data/repository/build.gradle.kts#L35

I'll try to make an android specific sample. If you have something you can push for me to see not working that would help as well. I probably won't be able to get to this until after the holidays. Thank you for the report

digitalbuddha avatar Dec 23 '22 13:12 digitalbuddha

Hey all

  • Reproduced here: https://github.com/howl-so/xplat/commit/4f7b3c4c77bcecb32a3148be433b6b3bb519310a
  • Fixed here: https://github.com/howl-so/xplat/commit/9c017cf418bf71ad6d327b1db80452390f88cc49
  • Note I am on 1.7.10 and I did not need to add the AtomicFU plugin

@digitalbuddha Will get up fix tn @SridharShanmugam Let us know if you continue to hit this

matt-ramotar avatar Dec 29 '22 23:12 matt-ramotar

@SridharShanmugam - Still hitting this unfortunately. Seems to be known Atomic FU issue. See https://github.com/Kotlin/kotlinx-atomicfu/issues/145. Will investigate https://github.com/touchlab/Stately as alternative. For now please add the dependency explicitly

matt-ramotar avatar Dec 30 '22 13:12 matt-ramotar

Updated README

matt-ramotar avatar Dec 30 '22 14:12 matt-ramotar

Thank you for the updated solution @matt-ramotar . I think you can mention adding the AtomicFU dependency using implementation instead of api in the Android section on Including Store In Your Project in the README file.

sridharshanmugam avatar Jan 02 '23 05:01 sridharshanmugam

How to reproduce the issue @matt-ramotar ? I tried https://github.com/howl-so/xplat/commit/4f7b3c4c77bcecb32a3148be433b6b3bb519310a , but no (store) issue.

aclassen avatar Jan 07 '23 01:01 aclassen

Hey! Sorry to be slow. After cloning the repo and checking out that commit, the app should crash at runtime

matt-ramotar avatar Jan 10 '23 16:01 matt-ramotar

Hmm, yes the app crashes but with a different exception (not inited lateinit). I worked around those issues so the app starts at least and request data. But no atomicFu exception .

aclassen avatar Jan 13 '23 22:01 aclassen

Just wanna note , we're using store4-kmp in our team published on private maven without any problems. I don't even provide atomicFu as "api" just as "implementation". The only difference i can spot so far is that i'm not using the atmicFu plugin as that's not needed if provided via "implementation"

aclassen avatar Jan 16 '23 21:01 aclassen