Can't add LocalBroadcastManager to project in Android Studio
Asked Answered
F

3

4

I think I've tried everything now...

I've been all over stack overflow, I've even consulted the android doc

Most of the posts here show how to add the .jar file in Eclipse "android tools -> add support library" or something

So I've tried to do it how the doc tells me, by going to build.gradle, and adding compile 'com.android.support:support-v4:19.0.0' to the dependencies

but even if I add it, and rebuild the project, I still can't import android.support.v4.content.LocalBroadcastManager... it doesn't even know what android.support is...

So is there anyone who can help me with this? the issue is getting very annoying, and it's slowed me down by hours...

Edit: I have updated the Android SDK, and made sure that the library exists in the sdk folder, so I know it's there... I just can't make android studio add it for some reason...

Edit 2: Only by navigating to the exact file path, manually, and then copying said path I was able to access the file... Still, I'd very much like to know what I can do to make this a more painless process...

Feldstein answered 13/1, 2014 at 2:30 Comment(1)
What version of Android Studio are you running? Also, please post your full build.gradle.Tetrabasic
S
19

Make sure your library got added successfully.

Check the following things.

1.Your build.gradle should be like

   dependencies {
          compile 'com.android.support:support-v4:19.0.+'
   }

2.File > Project Structure > Modules >Dependency Tab There should not be any red mark in dialog showing error if they are fix them.

enter image description here

3.Check your Module_Name.iml file

It should have this entry in last section

<orderEntry type="library" exported="" name="support-v4-19.0.0" level="project"/>

If its there with no entry close you studio delete .iml file and open studio again wait for gradle sync to be complete.You .iml file will be created again check for entry.

If every thing is fine do sync Your project with gradle again using this lovely tiny gradle button in toolbar.

enter image description here

Summertime answered 13/1, 2014 at 8:27 Comment(7)
please read what it says under "Edit:" I specifically put that there to not get the kind of answer you just gave me... note that I added the edit immediately after I posted the question.Feldstein
@ElectricCoffee your edit was not there when I read question and wrote the answer. It doesnt means that you down vote some one answer you is gonna try helping you. If you will make edit while writing answer how could I know. Atleast you should put comment before downvote.Summertime
I can't un-downvote it... sorry... you need to make an edit for me to do that, it was a haste desicion, and I immediately regretted doing it... but the first "Edit" was there from the very startFeldstein
the problem was that I didn't hit sync project with gradle files... I didn't think I needed to... sorry for the inconvenienceFeldstein
I had added it in my last answer. But I think you did not read and made me to edit that let me add that as well now so it can help others.Summertime
oh I did see it, and thanks for the solution... but it seemed weird to check it as the right answer after downvoting it...Feldstein
@ElectricCoffee don't worry it happens.Summertime
H
8

Try adding one of those dependencies to your app level build.gradle :

AndroidX

implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

Support Library

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

Then sync project with Gradle files.

Hendecahedron answered 27/8, 2019 at 11:58 Comment(5)
Hey @ElectricCoffee, I stumbled upon this question because I was having trouble with LocalBroadcastManager. Later, when I figured out what was wrong, I answered that for someone who would find themselves in my place. Thank you for asking the question though.Hendecahedron
@Vipul If your issue is not solved by these answers, post your issue as a separate Question and people will take a look over it.Hendecahedron
@Hendecahedron same question hereMime
for androidX: implementation "androidx.legacy:legacy-support-core-utils:1.0.0"Nuzzi
@ElectricCoffee it's 2023 and I found this answer useful.Taster
P
1

After lot of searching and R&D i found some solution. This is working for me i hope this is helping you.

implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'

If you not use Androidx please add this line

implementation 'android.legacy:legacy-support-core-utils:1.0.0'
Pleinair answered 29/5, 2021 at 11:9 Comment(1)
Haven't really used Android Studio in the 7 years since I posted that question, but I'm sure it'll help someone :)Feldstein

© 2022 - 2024 — McMap. All rights reserved.