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?

Jack
  • 1,825
  • 3
  • 26
  • 43

5 Answers5

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'
kostyabakay
  • 1,649
  • 2
  • 21
  • 32
wf9a5m75
  • 6,100
  • 3
  • 25
  • 59
  • 26
    For androidx you can use: `implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'` – Dennis van Dalen Feb 19 '19 at 08: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'` – kosiara - Bartosz Kosarzycki Apr 17 '21 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'
4

Use this

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

instead of

import androidx.core.content.LocalBroadcastManager;

Harsha Koshila
  • 141
  • 1
  • 2
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'
Saravit Soeng
  • 491
  • 4
  • 8
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'
Samset
  • 109
  • 7