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

Jack picture Jack · Jun 29, 2018 · Viewed 20.5k times · Source

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?

Answer

wf9a5m75 picture wf9a5m75 · Nov 20, 2018

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'