New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.NoSuchMethodError when classes are in different modules #576
Comments
any update on this or verfied this as a known issue or has been fixed? a class extended from either same library or a different library should yield same results. |
Sorry, seems like this issue slipped out of my sight. Can confirm this bug on 1.3.60 with mutli-module (library/app) setup |
Yes, this is still an issue. We are using Kotlin - 1.3.61 |
Kotlin 1.3.61 and Kotlin Serialization 0.14.0 is working for me, but with Kotlin 1.3.70:
|
I can confirm |
I tried the last eap 0.20.0 and it is working |
Yes, unfortunately, there's a breaking change in 1.3.70 plugin. We'll release compatible version of serialization in the following next few hours. Meanwhile, you can try eap builds from bintray: https://bintray.com/kotlin/kotlinx/kotlinx.serialization.runtime (e.g. |
Hmm, even the latest 0.20.0 is still failing for me with "no direct method " error using Kotlin 1.3.70 |
Original issue, which is a bug, not an incompatibility with Kotlin, is still present. @JavierSegoviaCordoba's issue was #736 |
Updated the versions to Kotlin - 1.3.70 Confirming that Issue is still there. |
@sandwwraith This issue is not the same as @JavierSegoviaCordoba is mentioning fixed. |
@sandwwraith Also I am not sure but I believe the fix would need @inherit added in the @Serialzable annotation so that this can be inherited across modules |
I had the same issue, any workaround on this ? |
I might have a workaround.. kotlin: 1.3.70, kotlinx-serialization: 0.20.0 I was running my newly created project on IntelliJ ever since i got "java.lang.NoSuchMethodError". I figure out, kotlinx plugin is not get activated when I run my test classes in IDE. I need to run [INFO] --- kotlin-maven-plugin:1.3.70:compile (compile) @ healthcheck --- so the serializer() function will be generated and exception will be gone right after you see the lines above. Hope it's solves your problem as well. === Edit: i'm still suffering when i move my data class to test module |
This bug seems to happen only in JVM targets, I'm able to serialize/deserialize with no issues on my JS target but on my JVM target that bug happens. In my case, I'm having this exception:
Edit: Changing kotlinx.serialization and Kotlin libs to |
kotlin: 1.3.70, kotlinx-serialization: 0.20.0 Fixed my issue |
I see how ppl are commenting that the issues are fixed in latest kotlin and kotlin serilzation plugin. Let me remind you guys to please understand the issue before commenting it's fixed and stop misleading everyone. And NO THIS ISSUE is not fixed in kotlin: 1.3.70, kotlinx-serialization: 0.20.0 |
Changing the Kotlin version forces clean building, which fixes the issue sometimes (when it's caused by incremental compilation in one module). |
Issue is NOT fixed. I have pushed test code outlined in original post #576 (comment) in this repo below. https://github.com/lallam/broke.git (A) if you compile above code and run AS-IS, app crashes at line 32 during deserialization in MainActivity [it is a very simple code] (B) to illustrate the multi project/module inheritance and deserialization issue. in libraryb, i have created a duplicate class ModelX (Same as Model from LibraryA) , and inherited the User class User - if you uncomment line 8 and comment line 9. problem goes away. serialize/deserialize should work regardless of, if Parent class is in At the moment. |
I'm new to android. @lallam, can you (or anyone) ELI5 how to set kotlinx-serialization? My build script is:
build.gradle:app is dependencies:
and my variable values are UPDATE: I guess it's no mystery on how to set kotlinx-serialization, but I am still getting the error:
|
Kotlin 1.3.72 still occurs |
Is there any progress on this one? This issue drives the library completly useless... |
- Replaced kotlinx serializer by gson serializer due to open issue in github Kotlin/kotlinx.serialization#576 - Replaced okhttp android client by ktor android client due to issues related to kotlin. It seems that it is related to latest version of okjhttp but even compiling with jvm target 1.8 is still failing: square/okhttp#4597
Reference: #576 (comment) this has become a critical issue for us. we are currently using a VERY crude method to over come this temporarily. Library A - Model Library B - Model extends LibraryA.Model Library C - Model extends LibraryA.Model Model classes in LibraryB and LibraryC are identical to LibraryA.Model and override the members. or other alternative is to abandon kotlin serialization altogether and refactor it to a different Library. fingers crossed. |
thanks @sandwwraith we will test and confirm. |
Hello, this is happening to me with Kotlin 1.4 and org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.0.0-RC which is included in Retrofit kotlinx serialization converter dependency (I could not use org.jetbrains.kotlinx:kotlinx-serialization-runtime-jvm:1.0-M1-1.4.0-rc since it creates dependency conflict). |
@IgnacioGarcia198 Do you have a sample project with reproducer? |
@sandwwraith I posted a project in my GitHub repository in order to reproduce it. Here is the link. |
Any update on this issue or example workaround? I'm experiencing this also in 1.4.10 |
maybe it has something to do with proguard obfuscation? |
@IgnacioGarcia198 don't use the serializer factory of retrofit instead accept the Retrofit response as Response Body objects and the write your own serializing extension api and convert the response body received to the required module using the modules serializer using kotlin serialization. |
Hi, I have the same error on my KMM project. java.lang.NoSuchMethodError: No direct method (Ljava/lang/String;Lkotlinx/serialization/internal/GeneratedSerializer;I)V in class Lkotlinx/serialization/internal/SerialClassDescImpl; or its super classes (declaration of 'kotlinx.serialization.internal.SerialClassDescImpl' appears in /data/app/com.example.mykmmclient12april-eQ9TG4Mg_9sDGC-WYU26Eg==/base.apk) Order Class - Environment: Kotlin version: [1.3.72] I doesn't want to update the kotlin and plugin version as it may affect my other projects. Please help. |
Okay Next is your "Order.Status" class serializable? Just check if it's not and make it serializable. Next this problem would only happen if you are extending a serializable class which is in a seperate module to a Serializable class which is in a different module, this problem would arise. So assuming you are facing the above problem, following are the solutions Hope this helps. Please share a sample piece of the above problem, so that we can take a closer look at the problem you are facing |
Hi, Thanks for the reply. But the "kotlin version" in the generated open api client project from the above link is - "1.3.50" which is very old and not compatible with KMM latest version which is "1.4.32". Note: I am trying to access the kotlin files or methods from swift ios standalone project. |
Runtime Crash
java.lang.NoSuchMethodError: No direct method (ILkotlinx/serialization/SerializationConstructorMarker;)V in class Lcom/xxxx/common/core/Model; or its super classes (declaration of 'com.xxxx.common.core.Model' appears in /data/app/com.xxxx.demo-PV-n86-hzEl-eyc8UqbACQ==/base.apk!classes7.dex)
10-11 15:30:10.048 E/AndroidRuntime(25760): at com.xxxx.reg.data.User.(Unknown Source:9)
10-11 15:30:10.048 E/AndroidRuntime(25760): at com.xxxx.reg.data.User$$serializer.deserialize(Unknown Source:624)
10-11 15:30:10.048 E/AndroidRuntime(25760): at com.xxxx.reg.data.User$$serializer.deserialize(User.kt:17)
10-11 15:30:10.048 E/AndroidRuntime(25760): at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:33)
To Reproduce
@serializable
abstract class Model(
var uniqueId: String = "",
}
@serializable
data class User(
var userName: String = "",
var dateOfBirth: String = "",
) : Model()
Library A - Model
Library B - User
I am getting the above crash.
BUT if I move the Model from Library A to Library B NO issues.
[Just an FYI]
if the variable uniqueId from Model is removed no issue
if @serializable is removed from Model no issues
Expected behavior
Not crash or throw fatal error.
Environment
Updated Post with More comments and Link to Code - #576 (comment)
The text was updated successfully, but these errors were encountered: