Investigating Wire and struggling to understand wh...
# squarelibraries
t
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
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
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
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
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
I would encourage having a shared proto-specific module as well