google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.43k stars 2.01k forks source link

Build failed with an exception. cannot access MediaBrowserServiceCompat #2269

Closed rhlmshr closed 3 years ago

rhlmshr commented 3 years ago

image

rhlmshr commented 3 years ago

Task :app:kaptDebugKotlin error: cannot access MediaBrowserServiceCompat class file for androidx.media.MediaBrowserServiceCompat not found Consult the following stack trace for details. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for androidx.media.MediaBrowserServiceCompat not found Task :app:compileDebugJavaWithJavac FAILED /Users/rahulmishra/StudioProjects/Blackboard Radio/app/build/generated/source/kapt/debug/com/curieo/podcast/ui/Hilt_BbrApplication.java:22: error: cannot find symbol return DaggerBbrApplication_HiltComponents_ApplicationC.builder() ^ symbol: variable DaggerBbrApplication_HiltComponents_ApplicationC 1 error

FAILURE: Build failed with an exception.

bcorso commented 3 years ago

This can happen if your MainPlayerService is in a separate Gradle module from your :app. For example, say you have :app -> :main_player_service -> "androidx.media:media". In such a case, while processing the component :app may need to access MediaBrowserServiceCompat but may not have a direct dependency on "androidx.media:media".

There are a few solutions.

  1. Add a direct dependency from :app -> androidx.media:media"
  2. Add an api (rather than implementation) dependency from :app -> project(":main_player_service")
  3. Once 239768b gets released in the next Hilt version you should be able to enable enableClasspathAggregation (we'll have more about this option in the release notes of the next release.
rhlmshr commented 3 years ago

Thanks. The resolution thats provided worked for me.

nlekkerman commented 3 years ago

Ok, how to fix the same error but with Java instead Kotlin?

bcorso commented 3 years ago

@nlekkerman, the issue is not specific to java or kotlin, so the suggestions in https://github.com/google/dagger/issues/2269#issuecomment-759584181 should still work if you are using Java.