Open aasitnikov opened 4 years ago
Same issue here. Is there any workaround?
I'm not good at kotlin. I hope someone can pull request. If anyone can implement this enhancement, I will be very grateful.
It is supported in 1.3.1
Great, thanks! Gave it a brief testing - seem to work nicely!
Was this causing a compilation or runtime error?
Was this causing a compilation or runtime error?
Without kotlin_module, if you would use your fat-aar artifact from other project, then Kotlin compiler wouldn't be able to find top-level extensions, and build would fail with "Unresolved reference"
I tested kotlin_module support it in my project - it seems to be working, if extension is declared directly in module with fat-aar plugin applied, but not if it's declared in embedded aar. I tried to manually edit resulting aar and put second kotlin_module inside classes.jar, but it doesn't seem to work
I tested kotlin_module support it in my project - it seems to be working, if extension is declared directly in module with fat-aar plugin applied, but not if it's declared in embedded aar. I tried to manually edit resulting aar and put second kotlin_module inside classes.jar, but it doesn't seem to work
I tested in example, It seem ok, you can check it.
I see now. In the :app module there's only one class - MainActivity.java. The original problem was about not being able to use top-level functions from Kotlin, if these functions was declared in module that was embeded. With version 1.3.1 it's working, only if top-level functions are declared in the module with fat-aar plugin applied.
Kotlin compiles top-level functions and properties into static functions of some "synthetic" class (it would be KotlinTestKt in example above, but you've changed it with annotation to KotlinTest2), and puts information about these functions and properties into kotiln_metadata file, so that other modules would be able to discover them. That's why these functions can be discovered from Java, but not from Kotlin, if kotlin_metadata is missing or corrupted.
To see the issue, you need to add some Kotlin file to :app module, and to try to call test2(), for example.
Currently, fat-aar plugin discards
*.kotlin_module
files (located in META-INF folder) of embedded modules. But they store info about top-level extension functions (and maybe regular top-level functions), and if*.kotlin_module
file discarded, compiler won't be able to find these functions. This blog post has some more explanation.*.kotlin_module
files can be read using handy kotlinx-metadata-jvm library.