1

We are trying implement LocalBroadcastManager in our Android app but facing "Cannot resolve" error.

This is the object we need - https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager

Included the library in app build.gradle (as stated in that page)

implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:localbroadcastmanager:28.0.0'

Included Maven in Solution build.gradle

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Gradle version is 5.4.1

Below line throws "Cannot resolve symbol" error

LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);

Please let me know what we might be missing. Appreciate your help.

Anice Jahanjoo
  • 7,088
  • 3
  • 20
  • 29
Krishnan V S
  • 1,124
  • 1
  • 13
  • 31
  • No we haven't. Do you recommend that we enable Jetifier and use Androidx as listed by "nice j" ? We haven't used Androidx so far, will it cause any compatibility issue with rest of libraries ? – Krishnan V S Sep 29 '19 at 05:55

3 Answers3

2

I checked it in Android Studio 3.5 and I didn't see any problem. but I use androidX and LocalBroadcastManager imported from androidx.localbroadcastmanager.content.LocalBroadcastManager;

Anice Jahanjoo
  • 7,088
  • 3
  • 20
  • 29
  • Thanks for your reply. Do you recommend that we enable Jetifier and use Androidx as listed by "nice j" ? We haven't used Androidx so far, will it cause any compatibility issue with rest of libraries ? – Krishnan V S Sep 29 '19 at 05:55
  • 1
    @KrishnanVS definitely I recommend it because Google is stopping support for com.android.support and you need to migrate.. I didn't have problem in my migrate but don't forget this https://stackoverflow.com/a/55932544/5282127 – Anice Jahanjoo Sep 29 '19 at 06:04
  • 1
    Great, thank you for the help. We will check this out right away and update the response. – Krishnan V S Sep 29 '19 at 06:09
1

I assume you enabled Jetifier therefore you shouldn't use support dependencies:

Replace

implementation 'com.android.support:support-v4:28.0.0' 
implementation 'com.android.support:localbroadcastmanager:28.0.0'

with

implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

Here's documentation for it: https://developer.android.com/reference/kotlin/androidx/localbroadcastmanager/content/LocalBroadcastManager

cycki
  • 188
  • 1
  • 4
  • 12
1

Thanks for the suggestions, migrating to androidx worked. We are getting the broadcast call to Receiver now. Appreciate the prompt help very much.

Krishnan V S
  • 1,124
  • 1
  • 13
  • 31