This message was deleted.
# android
s
This message was deleted.
e
correct, it can not. (at least not without some gross hacks)
c
OOOOOOOF
NOOOOOO
lol
Damn. I did not expect that being a constraint.
Is that something that's documented somewhere so i can show my team?
Any chance any one has suggestions on how to pass a simple dependency (like a string base url) to a java only module? The current way we have it done is that the old-network module is an android module, which depends on a core module (also android) and its read from there. I can maybe keep my new-network module as a jvm module, if my app module is the one that provides the URL down to the new-network module. But im not sure how I'd go about that... open to suggestions.
j
Do DI on the app module so you don’t need to depends on core
just pass the url via constructor and the app module build the necessary dependencies
c
Yeah, I guess that's my issue right now is that my
new-network
module is packaging in it's own dagger/hilt provides methods.
j
that shouldn’t be a problem
c
It kinda is though because the hilt provider methods in my new-network lib, need a base url that is going to come from :app module.
Unless I'm missing something simple here (sorry. im new to multi modules)
j
That is not a problem, the app will have all the dependencies and will be able to build
the app knows everything as it is like you instantiate the network client in the app, the app knows the client and the base url, you can call the constructor and pass the url in app, hilt will do that for you
c
So I have roughly something like this in my new-network module
Copy code
@Singleton
  @Provides
  fun providesApollo(I NEED A BASE URL HERE): ApolloClient = ApolloClient.Builder()
    .serverUrl(baseUrl)
    .build()
And from what you're saying it sounds like I would move that from
new-network
into
app
module.
j
yeah, you can provide the base url in app and it will work
I recommend you don’t provide it as string and create a wrapper, as string is too generic
you don’t need to move that
c
So would the provides method stay in
new-network
?
j
you just need to provide the base url in app, the app will build
c
Interesting. idk how that would even work.
but if you're saying its possible. ill give it a shot.
j
you can have a module with URL and another one with Client. client provides itself saying I need a URL. The URL module provides itself. App depends on both, it gets a client which needs a URL, and app has a URL, so it is able to build it
c
Wait. would that really work? It makes sense when you say it that way. but how would
new-network
know that the type exists? Let's say I create a new type like you said called BaseUrl or something. Wouldn't
new-network
now how to depend on
url-module
if I wanted the declaration to look like this
Copy code
@Singleton
  @Provides
  fun providesApollo(baseUrl: BaseUrl): ApolloClient = ApolloClient.Builder()
    .serverUrl(baseUrl)
    .build()
j
new network doesn’t know to know if it exists
c
But it still needs to know the Type or else the type will be unresolved, no
j
the app will fail, or not, when it tries to build if there is a missing dependency, in this case it is not missing as both are provided
the type needs to be shared between both modules, of course
but not the value you provide to the type
c
Correct, so that's the point I'm getting at.
j
you can test it with a string so you don’t need to share a type
c
Yeah. I'm going to try that now.
What you're saying of
Copy code
app
        /      \
url-module     network-module
and url and network dont know about each other and app is the thing that glues everything together makes sense.
@Javi yeah! That worked! TIL that the diagram above works. I thought network-module was essentially self contained and dependencies wouldn't be passed down into it for some reason.
I think I want to create some sort of BaseUrl class to use instead of string (like you said), but right now I have analysis paralysis on where that class would be defined. Seems like if I defined it in a
url-module
then I would HAVE to have network module depend on url-module
j
Ideally a value class but I think it won’t work with dagger
c
I'm just doing @named for now and it works well. I need to figure out whether I should create some sort of jvm module for a shared type. but it seems overkill right now for just passing a url from app to new-network.