Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not resolve import LocalBroadcastManager on statement android.support.v4.content.LocalBroadcastManager;

I got this error while importing an eclipse project to Android studio. It shows a suggestion Add library Gradle: com.android.support:support-core-utils-27.1.1 to classpath. I have added the library in my build.gradle file.

Here is my gradle file.

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "28.0.0"

defaultConfig {
    applicationId "com.example.tracking"
    minSdkVersion 17
    targetSdkVersion 27
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

allprojects {
repositories {
    google()

}
}

dependencies {


implementation project(':asciiProtocol')
implementation project(':deviceList')
implementation project(':captureActivity')
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation "com.android.support:support-core-utils:27.1.1"
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.code.gson:gson:2.8.2'
implementation files('libs/opencsv-2.3.jar')
implementation files('libs/rfid.reader.api.jar')
implementation files('libs/scannercontrol.jar')
implementation files('libs/Zebra.jar')

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.1'
            }
        }
    }
}
}

I googled it but I could not find a proper solution for this. However, I tried the solution from this that isn't the right solution. Any help is appreciated?

like image 542
Jack Avatar asked Jun 29 '18 08:06

Jack


3 Answers

I faced the same problem, then I noticed Google divided the v4 support library to multiple packages.

Note: Prior to Support Library revision 24.2.0, there was a single v4 support library. That library was divided into multiple modules to improve efficiency. For backwards compatibility, if you list support-v4 in your Gradle script, your APK will include all of the v4 modules. However, to reduce APK size, we recommend that you just list the specific modules your app needs.

https://developer.android.com/topic/libraries/support-library/packages#v4

Then I checked LocalBroadcast page. https://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager

At the page top, there is description

belongs to Maven artifact com.android.support:localbroadcastmanager:28.0.0-alpha1

When I faced this problem, the v28.0.0 (not alpha) has been available.

In the end, I changed settings in my build.gradle.

before

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

after

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

AndroidX

implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
like image 112
wf9a5m75 Avatar answered Oct 18 '22 22:10

wf9a5m75


This happened to me while migrating for AndroidX and the solution was to replace "import androidx.core.content.LocalBroadcastManager;" with import androidx.localbroadcastmanager.content.LocalBroadcastManager;

Edited, as required to include the implementation, please don't forget dependency:

implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

Noting that Target & Build version are:

compileSdkVersion 29
buildToolsVersion '29.0.2'
like image 27
صلي علي محمد Atef Farouk Avatar answered Oct 18 '22 22:10

صلي علي محمد Atef Farouk


Use this

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

instead of

import androidx.core.content.LocalBroadcastManager;

like image 4
Harsha Koshila Avatar answered Oct 18 '22 23:10

Harsha Koshila