Dagger 2 cannot access Retrofit
I found the problem, was in the build.gradle ... My retrofit instance was in a separate module. This module is a api:
App build.gradle
api project(':data')
And I was using implementation in the retrofit dependencies. I changed to api and the problem was fixed.
api "com.squareup.retrofit2:retrofit:$retrofit_version"
api "com.squareup.retrofit2:converter-gson:$retrofit_version"
The accepted answer works but using the api
function exposes all the other libraries used by the data
module to the app
module. To avoid this just add the retrofit dependencies to your app module or where ever you need the dependencies.
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
Above goes to the app
module's Gradle file. If your Retrofit instance also has other dependencies such as RxJava2CallAdapterFactory
do not forget to add these depencies too.