https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
t

Tolriq

02/21/2024, 7:51 PM
Investigating Wire and struggling to understand what's the proper way to share the proto definition and probably generated code. Goal is to exchange data between a phone app and wear app in the same project with common modules. Should I just have a sharedmodule with the proto and the generator and it will work? Or should I just put the proto files in a shared module and add that module in both apps via
Copy code
sourcePath {    srcProject()}
?
y

yschimke

02/21/2024, 8:13 PM
Confetti uses the first option. A shared module with the wire plugin, and used from both wear and mobile app modules.
I think the benefit is that you often have a layer of shared code using those types, and this allows you to reuse those that.
What is your use case? Sharing data via a remote API? Or over the Wearable DataClient/MessageClient?
t

Tolriq

02/21/2024, 8:21 PM
Both actually, shared state / settings, some messages and streaming client or http for larger data exchanges.
If the shared module works then I'll go that road better for compile times too. Thanks.
y

yschimke

02/21/2024, 8:26 PM
Horologist has an implementation of Androidx DataStore on the Wearable DataClient that might fit your needs. The owner is a DataStore, and the remote side just gets a Flow. Used here in Confetti https://github.com/joreilly/Confetti/blob/531c5a9fc8bfd997eca95fef8bf6c9035e831b2c[…]src/main/java/dev/johnoreilly/confetti/wear/WearSettingsSync.kt and a serializer https://github.com/joreilly/Confetti/blob/531c5a9fc8bfd997eca95fef8bf6c9035e831b2c[…]lin/dev/johnoreilly/confetti/settings/WearSettingsSerializer.kt
t

Tolriq

02/21/2024, 8:33 PM
Ho nice thanks a lot, avoid me to look into that, looks easy. I guess until I discover all the edge cases of protobuf code gen :)
b

Benoit Quenaudon

02/21/2024, 9:28 PM
I would encourage having a shared proto-specific module as well