26

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?

1
  • Did you try to Clean Project and then Make Project in android studio's Build tab?
    – Vall0n
    Jun 29, 2018 at 8:12

5 Answers 5

41

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'
2
  • 26
    For androidx you can use: implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' Feb 19, 2019 at 8:59
  • you can now replace implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' with the new: implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' & 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' Apr 17, 2021 at 23:22
28

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'
3
  • As called out by Dennis in another answer, make sure you include the dependency too: implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' Feb 4, 2020 at 0:19
  • This solution worked great at SDK version 28 but in SDK version 29 this doesn't solve problem. Feb 28, 2020 at 9:29
  • the solution is working for : ' compileSdkVersion 29 buildToolsVersion '29.0.2' ' Mar 1, 2020 at 8:04
4

Use this

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

instead of

import androidx.core.content.LocalBroadcastManager;

2

For newer Android version, you should try to add this to gradle.properties

android.enableJetifier=true

and then add this dependency to build.gradle

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
1
  • the dependency is correct but no need for android.enableJetifier=true
    – Arlind
    Jan 18, 2022 at 14:39
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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.