https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
l

Landry Norris

06/15/2022, 9:58 PM
I noticed that androidx annotations is still an android-only library. With Compose and Datastore being experimentally KMM, is there any plan to move annotations over? This would help with models that I want to keep in commonMain, but may need annotations such as Keep (I need to access one model class via reflection in one project). Some, such as Discouraged, AnyThread, DoNotInline, ReturnThis, etc. may even be meaningful or useful in shared code.
e

ephemient

06/15/2022, 10:07 PM
(your point still stands about usability from multiplatform, but it's not Android-only)
l

Landry Norris

06/15/2022, 10:12 PM
Good to know that it is also available on the JVM. I wonder what the reason was for not making it available on others as well? For some (especially reflection-related), it makes sense that they are only useful on JVM, but sometimes I still need shared code classes to behave a certain way on the JVM, but a no-op on other platforms is fine. Some are also fully meaningful on other platforms.
e

ephemient

06/15/2022, 10:13 PM
all the amdroidx annotations were written in Java
at this point I believe one is written in Kotlin, but that is far from making the whole library available multiplatform
l

Landry Norris

06/15/2022, 10:16 PM
I see. Changing it to Kotlin doesn't seem like it would be too hard, but I can also see that there are more important things for the androidx team to work on.
If I expect/actual an annotation, I'd assume it still works, right? I mainly need Keep right now so I can use one class via reflection.
e

ephemient

06/15/2022, 10:19 PM
I am not 100% sure if it'll work with Android Lint, but it should work with reflection and r8
you might want
@OptionalExpectation expect annotation class Keep
so you only have to define
actual typealias Keep
in a JVM sourceset and leave it un-actualized in the JS/native sourcesets
l

Landry Norris

06/15/2022, 10:21 PM
That's interesting. I'll do that.
k

Kamil Kalisz

06/16/2022, 7:16 AM
I can confirm that expect/actual works i did this for Parcelize annotation. You can check https://ankushg.com/posts/multiplatform-parcelize/
144 Views