infinum/kotlin-jsonapix

Library doesn't work with multi-module project

graisVictory opened this issue · 4 comments

Hi! Thanks for all your work! Library doesn't work with multi-module project because it generates the same classes with same packages for each module :(

Hi @graisVictory ,

It would be great if you can specify in which way the library has been used in your case. I've double tested the library in multi module projects and all seems to be working as expected. There might be some other issue we're not aware of that is causing problems in your setup.

We would appreciate a bit more information about the issue you're experiencing so we can act accordingly :)

Kind regards

Hi @stjepanbanek, I have encounter issues with multi-modules project as well.

There are two issues.

  1. When there are multi modules depending on the library. It will have error in mergeLibDex
Caused by: com.android.tools.r8.internal.f: Type com.infinum.jsonapix.JsonXExtensions$format$1 is defined multiple times: .....

Seems to me, that's caused by there is a JsonXExtension.kt for each module. And they all contains property format.

  1. ClassA and ClassB are in different modules and instance of ClassB is property of ClassA.

In :moduleA

@Serializable
@JsonApiX(type = "classA")
data class ClassA(
   @HasOne(type="classB")
    val classB: ClassB
)

In :moduleB

@Serializable
@JsonApiX(type = "classB")
data class ClassB(
    val foo: String
)

When compiling :moduleA, an error will be thrown.

JsonXExtensions.kt: (): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
OtherClass.toResourceObject()
AnotherClass.toResourceObject()

Please let me know if I have done anything incorrect. Thanks!

Hi @howardtamhk!

Can you share your dependency setup from the project and module level build.gradle files?

I suspect you might be right about JsonXExtensions being generated twice.

I will test myself when I get the chance. If I can reproduce the issue, I will add it to the planned fixed for the next release.

Thanks for using the lib and the feedback! And for the patience :)

Thanks @stjepanbanek!

I've created a quick sample https://github.com/howardtamhk/JsonApiXTest. Let me know if you cannot reproduce the issues.