Related
Trying to create a simple app with FireStore and Google Authentication. Having problem with the gradle:
In project 'app' a resolved Google Play services library dependency
depends on another at an exact version (e.g. "[15.0. 1]", but isn't
being resolved to that version. Behavior exhibited by the library will
be unknown.
Dependency failing: com.google.android.gms:play-services-flags:15.0.1
-> com.google.android.gms:play-services-basement#[
15.0.1], but play-services-basement version was 16.0.1.
The following dependencies are project dependencies that are direct or
have transitive dependencies that lead to the art ifact with the
issue.
-- Project 'app' depends onto com.google.firebase:firebase-firestore#17.1.5
-- Project 'app' depends onto com.firebaseui:firebase-ui-auth#4.2.0
For extended debugging info execute Gradle from the command line with
./gradlew --info :app:assembleDebug to see the dep endency paths to
the artifact. This error message came from the google-services Gradle
plugin, report issues at https://
github.com/google/play-services-plugins and disable by adding
"googleServices { disableVersionCheck = false }" to your b uild.gradle
file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "myapp.com"
minSdkVersion 19
targetSdkVersion 27
versionCode 11
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin
Project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
Can somebody help me?
There are many answers here for individual solutions that do not really get down to the problem. Here is how to solve this in general:
As the original log output suggests, it is useful to run the build in the terminal with the following command:
./gradlew --info assembleDebug
This will give you a list of all dependencies that are involved in the conflict. It looks similar to this (I removed the package name stuff to make it a bit more readable):
Dependency Resolution Help: Displaying all currently known paths to any version of the dependency: Artifact(groupId=com.google.firebase, artifactId=firebase-iid)
-- task/module dep -> firebase-analytics#17.2.0
---- firebase-analytics:17.2.0 library depends -> play-services-measurement-api#17.2.0
------ play-services-measurement-api:17.2.0 library depends -> firebase-iid#19.0.0
-- task/module dep -> firebase-core#17.2.0
---- firebase-core:17.2.0 library depends -> firebase-analytics#17.2.0
------ firebase-analytics:17.2.0 library depends -> play-services-measurement-api#17.2.0
-------- play-services-measurement-api:17.2.0 library depends -> firebase-iid#19.0.0
-- task/module dep -> play-services-measurement-api#17.2.0
---- play-services-measurement-api:17.2.0 library depends -> firebase-iid#19.0.0
-- task/module dep -> firebase-iid#19.0.0
-- task/module dep -> firebase-messaging#17.1.0
---- firebase-messaging:17.1.0 library depends -> firebase-iid#[16.2.0]
-- task/module dep -> com.pressenger:sdk#4.8.0
---- com.pressenger:sdk:4.8.0 library depends -> firebase-messaging#17.1.0
------ firebase-messaging:17.1.0 library depends -> firebase-iid#[16.2.0]
From this list you get to know 2 things:
Where is the conflicting depedency found
What versions of the conflicting dependency are set up
In my case the conflicting dependency is firebase-iid: It's either #19.0.0 or #16.2.0
To fix this you must define the top-level dependency of the wrong firebase-iid explicitly in your build.gralde.
So in the upper log you can see that there are 2 examples of an out-dated version of firebase-iid#16.2.0. One comes from -- task/module dep -> firebase-messaging#17.1.0 the other one from a third-party library (pressenger). We don't have influence on the third-party library, so nothing to do here.
But for the other dependency, we have to declare it explicitly with the correct version:
implementation 'com.google.firebase:firebase-messaging:20.0.0'
Now the build works again. Happy ending :)
There's a known bug with Google Services 4.2.0 that may cause this. Downgrading your google-services version to 4.1.0 in your project's build.gradle may resolve the issue
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.1.0' //decreased from 4.2.0
}
}
The problem was it was missing a dependency.
Adding com.google.firebase:firebase-auth solved the issue.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-firestore:17.1.5'
// implementation'com.google.firebase:firebase-core:16.0.6'
// implementation'com.google.firebase:firebase-storage:16.0.5'
implementation'com.google.firebase:firebase-auth:16.1.0' => add this line
implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
}
There was a bug related to google-services that was eventually fixed in version 4.3.3.
So you can either use 4.3.3 or the latest version (check here)
classpath 'com.google.gms:google-services:4.3.3' // or latest version
or downgrade to 4.1.0
classpath 'com.google.gms:google-services:4.1.0'
i added the latest version of firebase messaging to build.gradle (Module: app) in my project and problem solved
implementation 'com.google.firebase:firebase-messaging:20.0.0'
Your app/build.gradle might have these lemon color blocked on dependencies part in Android Studio like on the picture below,
These (lemon color blocks) mean it's not latest version of dependency. just put mouse on each block, then IDE (Android Studio) tells the numbers that have to be changed.
Updating all my Google Play Services libraries to the latest in ALL modules solved the issue for me. I don't see that you have any Google Play Services libraries, but I wanna leave this answer here to those that might find this useful.
My project was working fine (No build issues). All of a sudden, I got this error
"resolved Google Play services library dependency depends on another at an exact version.."
I figured out that it was because I was building offline.
If anyone gets the same error, check if you are building offline.
Thanks, but unfortunately, this didn't entirely work for me. I also had to add the following to my build.grade (Module:app)
implementation 'com.google.android.gms:play-services-flags:16.0.1'
implementation 'com.google.android.gms:play-services-basement:16.0.1'
The problem was fixed after upgrading this lib in my project's build.gradle:
classpath 'com.google.gms:google-services:4.3.3'
and these ones in the app module's build.gradle:
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-messaging:20.1.5'
After this, use Android Studio's Clean menu
I am using One Signal and caught this error once a time.
The reason was:
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: 'com.android.application'
to put apply plugin for one signal before 'com.android.application'.
Maybe this will be useful for some other apply plugin too.
Add FCM to your App added Lower dependency Then I changed the dependency to the latest version this problem has solved.
compile 'com.google.firebase:firebase-messaging:17.3.4'
to
implementation 'com.google.firebase:firebase-messaging:20.0.0'
None of the other answers worked for me. My use-case is with React-Native 61+ trying to setup FCM and Analytics. What worked for me was using the latest google-services in android/build.gradle
dependencies {
classpath "com.android.tools.build:gradle:3.4.2"
classpath "com.google.gms:google-services:4.3.3" // Need the latest here
}
And then adding the gradle dependencies to android/app/build.gradle required for the products I'm using (in my case Analytics and Cloud Messaging) from here
dependencies {
...
// add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
...
}
I just tried #live-love's accepted answer myself and agree with the approach.
It might be more precise, however, to correct your dependencies according to the latest Google Services library version.
For my case, it happened when I just added/activated a Firebase service to the app.
You need to follow the latest version in project and Gradle app.
My app/build.gradle
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//Android Support Design Library
implementation 'com.android.support:design:27.1.1'
//RecyclerView
implementation 'com.android.support:recyclerview-v7:27.1.1'
// Support multidex
implementation 'com.android.support:multidex:1.0.3'
// Firebase Core
// implementation 'com.google.firebase:firebase-core:16.0.1'
//Firebase Authentication
implementation 'com.google.firebase:firebase-auth:19.3.1'
// Firestore Firestore
implementation 'com.google.firebase:firebase-firestore:21.4.3'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
// glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
// Circle ImageView
implementation 'de.hdodenhof:circleimageview:2.2.0'
}
apply plugin: 'com.google.gms.google-services'
My project's build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Don't forget to sync the Gradle again.
The working solution for me was to remove "firebase-auth" and add "firebase-core" dependency. But after a couple of project rebuilds I started experiencing another compilation issue so I had to add the "firebase-auth" dependency in addition to the "firebase-core" in order to make it work:
implementation 'com.google.firebase:firebase-auth:19.0.0'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
Add the line below in you Project's build.gradle (See image below)
classpath 'com.google.gms:google-services:4.3.3'
Then update your Firebase related packages by going to :
File > Project Structure > Dependencies > app
Update Firebase modules to latest version (See the image below)
In my case I am using :
implementation 'com.google.firebase:firebase-database:19.3.0'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-messaging:20.1.7'
implementation 'com.google.firebase:firebase-core:17.4.0'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
Don't forget to add :
apply plugin: 'com.google.gms.google-services'
See my Module's build.gradle file below.
The ML Kit library had versioning problems in the latest release.
Google Play services library dependency depends on another at an exact version error (thrown by the google-services plugin)
Here is the link to the solution.
https://firebase.google.com/support/release-notes/android#bom_v25-8-0
This is new thing happen to me that If your network is not secure and you are getting prompt of Untrusted Certificate.
If you will Accept or Reject, It will give this error until your network will not be secure.
You can work offline by checking Setting -> Gradle -> Offline Mode
If you used song haesuk answer, you need to do it for both build.gradle Project (classpath in dependencies), and in build.gradle app (implementations). Also do the same if you change builds for any libraries imported to the app.
I use suggestions provided by android studio and it changed implementations but did not change dependencies hence during build, there was a conflict between the two and it gave me same error.
I replicated the issue when I accidentally added com.google.firebase:firebase-ml-vision twice with different versions.
I resolved it by simply clearing the app-level dependencies block leaving just the default Android dependencies like so:
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'androidx.multidex:multidex:2.0.0'
}
This worked for me!
dependencies {
classpath "com.android.tools.build:gradle:3.4.2"
classpath "com.google.gms:google-services:4.3.3" // Need the latest here
}
dependencies {
...
// add the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
...
}
In my case updating the firebase-bom and play services library to their latest version solved the issue:
In app level gradle :
implementation platform('com.google.firebase:firebase-bom:30.3.2')
In project level gradle :
classpath 'com.google.gms:google-services:4.3.13'
I'm using Android Studio 3.2 Beta5 to migrate my project to AndroidX. When I rebuild my app I got these errors:
ERROR: [TAG] Failed to resolve variable '${animal.sniffer.version}'
ERROR: [TAG] Failed to resolve variable '${junit.version}'
Full clean & rebuild did not work! Anyone know how to fix this?
gradle.properties
android.enableJetifier=true
android.useAndroidX=true
build.gradle
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-beta05'
classpath 'com.google.gms:google-services:4.0.1'
classpath "io.realm:realm-gradle-plugin:5.3.1"
classpath 'io.fabric.tools:gradle:1.25.4'
classpath 'com.google.firebase:firebase-plugins:1.1.5'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.firebase-perf'
android {
compileSdkVersion 28
buildToolsVersion "28.0.0"
defaultConfig {
applicationId "com.iceteaviet.fastfoodfinder"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
aaptOptions {
cruncherEnabled = false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
implementation 'androidx.cardview:cardview:1.0.0-rc01'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'io.realm:realm-android-library:5.3.1'
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.0.2'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
implementation 'com.google.firebase:firebase-perf:16.0.0'
implementation 'com.jakewharton.timber:timber:4.7.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}
apply plugin: 'com.google.gms.google-services'
I fix this with two steps
1) File -> Invalidate Caches / restart...
2) Build -> Clean project
I got the same error after updating my build.gradle file with AndroidX Test dependencies. Turns out I forgot to remove the old junit dependency. So for me, the fix was simply to remove the following dependency:
dependencies {
...
testImplementation 'junit:junit:4.12'
}
Adding Java 8 support to build.gradle file fixed issue for me
android {
...
//Add the following configuration in order to target Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
It seems to be Glide the problem.
I had the same error and I just updated the Glide's dependencies to 4.8 and there is no build errors.
Kotlin :
// Glide
def glide_version = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
Java :
// Glide
def glide_version = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glide_version"
annotationProcessor "com.github.bumptech.glide:compiler:$glide_version"
Be sure to have enabled in your gradle.properties :
android.useAndroidX=true
android.enableJetifier=true
Source : https://github.com/bumptech/glide/issues/3124
Hope this will help you!
Fixed it by going to the main directory and typing flutter clean
Removing the testInstrumentationRunner worked for me:
defaultConfig {
...
...
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
If you're using Kotlin, the issue will popup if don't use the kapt version for any annotation processor you use in the project.
As #Vince mentioned the case with Glide, this could happen with Dagger2, Butterknife, etc.
If you're using both Java and Kotlin you'll need to keep both dependencies, as follows (were $glideVersion is a predefined version of Glide):
implementation "com.github.bumptech.glide:glide:$glideVersion"
kapt "com.github.bumptech.glide:compiler:$glideVersion"
If you're on a Kotlin only project, the kapt dependency should work alone.
EDIT
Another thing you should have in mind is if you're already using Androidx. Androidx is a great refactor but when migrating it can cause some of your dependencies to collapse. Mainstream libraries are already updated to Androidx, however, some of them are not and even won't.
If the issue doesn't go away with my provided solution above this edit, you can take a look at your dependencies and make sure they use Androidx as well.
EDIT 2
As #Ted mentioned, I researched back and he's right kapt does handle java files as well. kapt alone will do the trick, no need to keep both kapt and annotationProcessor dependencies.
Try removing this line:
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
from the buildscript / repositories section of your build.gradle file.
When I added that line, I got the error you described. When I removed it, no longer. That line should only be in the allprojects / repositories section.
Try set android.enableJetifier=false in gradle.properties. Then Invalidate Caches / Restart ... in Android Studio
The fix is in 4.2.0, use the higher version of google gms jar.
Try changing:
classpath 'com.google.gms:google-services:4.0.1'
by this version:
classpath 'com.google.gms:google-services:4.2.0'
Hope this works...
If you are using dagger or butterknife, please make sure to update it to the latest version. Or, if you have another injection library used in your project, you can try to check it if it support androidx or no.
I've found same error, the problem is on my dagger and butterknife. Have fixed it by updating it to newest version.
Android version: 4.10.2
I solved this issue with three simple steps:
First i added below this in pubspec.yml:
(with two spaces of identation)
module:
androidX: true
Adding this two lines below in gradle.properties, i have this in android/gradle.properties, in the project folder.
android.useAndroidX=true
android.enableJetifier=true
And after this i wrote with the terminal:
flutter clean
Maybe you will have to stop the device and run again.
I fixed this by updating the firebase dependencies to the latest.
I faced this error after adding butterknife to my project.
In order to resolve this error you should use Java8.
I would recommend this answer.
How I resolved it:
1.add following code in build.gradle (module: app)
android {
...
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
clean prject and run.
I fixed it by refreshing the cahche (Instead of invalidating it - which also clears the local history):
in gradle.properties file, comment the line org.gradle.caching=true.
Clean, Rebuild.
in gradle.properties file, un-comment the line
org.gradle.caching=true.
Clean, Rebuild.
Thats it!
Go to file and click on Invalidate caches and restart.
After it restarts then you increase the minimum SDK version in your app's build.gradle file.
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?
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'
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'
Use this
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
instead of
import androidx.core.content.LocalBroadcastManager;
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'
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'
I am new to Android App Development. When I tried to create a new project,Android Project...the following message popped up..
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]
This is the screenshot of my project
click here to see screenshot of the error i got
i also tried adding this code to my dependency..
androidTestCompile 'com.android.support:support-annotations:23.3.0'
this didn't work out. I also tried 27.1.1 and 26.1.0..
that didn't work out either.
Based on your screenshot i found two working solutions:
First solution: add to dependencies of your gradle module this line
compile 'com.android.support:support-annotations:27.1.1'
and sync your project
Note: if you are using Android studio 3+ change compile to implementation
Second solution: Configure project-wide properties found in the documentation https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties
in project gradle add this line:
// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
// The following are only a few examples of the types of properties you can define.
compileSdkVersion = 26
// You can also use this to specify versions for dependencies. Having consistent
// versions between modules can avoid behavior conflicts.
supportLibVersion = "27.1.1"
}
Then to access this section change compileSdkVersionline to be
compileSdkVersion rootProject.ext.compileSdkVersion
and at dependencies section change the imported library to be like this:
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
and sync your project
Note: if you are using Android studio 3+ change compile to implementation
For the difference between compile and implementation look at this
What's the difference between implementation and compile in gradle
Add the below line in your app.gradle file before depencencies block.
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
}
}
There's also screenshot below for a better understanding.
the configurations.all block will only be helpful if you want your target sdk to be 26. If you can change it to 27 the error will be gone without adding the configuration block in app.gradle file.
There is one more way if you would remove all the test implementation from app.gradle file it would resolve the error and in this also you dont need to add the configuration block nor you need to change the targetsdk version.
If you use version 26 then inside dependencies version should be 1.0.1 and 3.0.1 i.e., as follows
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
If you use version 27 then inside dependencies version should be 1.0.2 and 3.0.2 i.e., as follows
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
If you using Android Studio 3.1.+ or above
just put this in your gradle depedencies:
implementation 'com.android.support:support-annotations:27.1.1'
Overall like this:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-annotations:27.1.1'
}
This is due a conflict of versions, to solve it, just force an update of your support-annotations version, adding this line on your module: app gradle
implementation ('com.android.support:support-annotations:27.1.1')
Hope this solves your issue ;)
Edit
Almost forgot, you can declare a single extra property (https://docs.gradle.org/current/userguide/writing_build_scripts.html#sec:extra_properties) for the version, go to your project (or your top) gradle file, and declare your support, or just for this example, annotation version var
ext.annotation_version = "27.1.1"
Then in your module gradle replace it with:
implementation ("com.android.support:support-annotations:$annotation_version")
This is very similar to the #emadabel solution, which is a good alternative for doing it, but without the block, or the rootproject prefix.
Adding this to build.gradle (Module app) worked for me:
compile 'com.android.support:support-annotations:27.1.1'
Don't worry It is simple:
Go to the "Project" Directory structure and in that go to "Gradle Scripts" and inside it go to "build.gradle (Module:app)" and double click it.
Now -
Scroll down the program and in that go to the dependencies section :
Like below
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Now in this Delete the last two lines of code and rebuild the app and now it will work
The dependencies should be:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
}
REBUILD THE APP AND IT WORKS !!
Go to the build.gradle(Module App) in your project:
Follow the pic and change those version:
compileSdkVersion: 27
targetSdkVersion: 27
and if android studio version 2:
Change the line with this line:
compile 'com.android.support:appcompat-v7:27.1.1'
else
Change the line with this line:
implementation 'com.android.support:appcompat-v7:27.1.1'
and hopefully, you will solve your bug.
Add this to your gradle file.
implementation 'com.android.support:support-annotations:27.1.1'
Another simple way to solve this problem is to edit your build.gradle (app):
Go to android tag and change compileSdkVersion 26 to compileSdkVersion 27
Go to defaultConfig tag and change targetSdkVersion 26 to targetSdkVersion 27
Got to dependencies tag and change implementation 'com.android.support:appcompat-v7:26.1.0' to implementation 'com.android.support:appcompat-v7:27.1.1'
I have the same problem, in build.gradle (Module:app)
add the following line of code inside dependencies:
dependencies
{
...
compile 'com.android.support:support-annotations:27.1.1'
}
It worked for me perfectly
Important Update
Go to project level build.gradle, define global variables
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlinVersion = '1.2.61'
ext.global_minSdkVersion = 16
ext.global_targetSdkVersion = 28
ext.global_buildToolsVersion = '28.0.1'
ext.global_supportLibVersion = '27.1.1'
}
Go to app level build.gradle, and use global variables
app build.gradle
android {
compileSdkVersion global_targetSdkVersion
buildToolsVersion global_buildToolsVersion
defaultConfig {
minSdkVersion global_minSdkVersion
targetSdkVersion global_targetSdkVersion
}
...
dependencies {
implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
// and so on...
}
some library build.gradle
android {
compileSdkVersion global_targetSdkVersion
buildToolsVersion global_buildToolsVersion
defaultConfig {
minSdkVersion global_minSdkVersion
targetSdkVersion global_targetSdkVersion
}
...
dependencies {
implementation "com.android.support:appcompat-v7:$global_supportLibVersion"
implementation "com.android.support:recyclerview-v7:$global_supportLibVersion"
// and so on...
}
The solution is to make your versions same as in all modules. So that you don't have conflicts.
Important Tips
I felt when I have updated versions of everything- gradle, sdks,
libraries etc. then I face less errors. Because developers are working
hard to make it easy development on Android Studio.
Always have latest but stable versions Unstable versions are alpha, beta and rc, ignore them in developing.
I have updated all below in my projects, and I don't face these errors anymore.
Update Android Studio (Track release)
Project level build.gradle - classpath 'com.android.tools.build:gradle:3.2.0' (Track android.build.gradle release & this)
Have updated buildToolVersion (Track buildToolVersion release)
Have latest compileSdkVersion and targetSdkVersion Track platform release
Have updated library versions, because after above updates, its necessary. (#See How to update)
Happy coding! :)
If changing target sdk version doesn't help then if you have any dependency with version 3.0.2 then change it to 3.0.1.
e.g change
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
to
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.1'
A better solution is explained in the official explanation. I left the answer I have given before under the horizontal line.
According to the solution there:
Use an external tag and write down the following code below in the top-level build.gradle file. You're going to change the version to a variable rather than a static version number.
ext {
compileSdkVersion = 26
supportLibVersion = "27.1.1"
}
Change the static version numbers in your app-level build.gradle file, the one has (Module: app) near.
android {
compileSdkVersion rootProject.ext.compileSdkVersion // It was 26 for example
// the below lines will stay
}
// here there are some other stuff maybe
dependencies {
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
// the below lines will stay
}
Sync your project and you'll get no errors.
You don't need to add anything to Gradle scripts. Install the necessary SDKs and the problem will be solved.
In your case, install the libraries below from Preferences > Android SDK or Tools > Android > SDK Manager
Add this line under the dependencies in your gradle file
compile 'com.android.support:support-annotations:27.1.1'
I know about this questions:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]
And I've read this documentations:
Migrate to Android Plugin for Gradle 3.0.0
Migrating to Android 8.0
So I'm posting this question believing its not a duplicate.
I've installed Android Studio 3.0.1. I didn't have any previous version before and I started a new project.
Every setting in Gradle file have been set by Android Studio itself and I've checked them all.
These are the file contents:
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.administrator.as301test"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Top level build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
I use google() in repositories as here clearly says:
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
My gradle version is 4.1 so I don't need above code.
But I still get this error as the others have been asking about:
Error:Unable to resolve dependency for ':app#debug/compileClasspath':
Could not resolve com.android.support:appcompat-v7:26.1.0.
Why should I get this error when I'm creating a new project in AS 3.0.1 and it has been set all the necessary settings?
Update
#Rohit's answer somehow solved the issue but I still get same error for some other dependencies.
Could not resolve com.android.support.test:runner:1.0.1
Could not resolve
com.android.support.test.espresso:espresso-core:3.0.1
Could not resolve junit:junit:4.12
Finally I fixed the problem by modifying build.gradle like this:
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
}
I've removed these lines as these will produce more errors:
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Also I had same problem with migrating an existing project from 2.3 to 3.0.1 and with modifying the project gradle files like this, I came up with a working solution:
build.gradle (module app)
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.mobaleghan.tablighcalendar"
minSdkVersion 16
targetSdkVersion 27
}
dependencies {
implementation 'com.android.support:appcompat-v7:25.1.0'
implementation 'com.android.support:design:25.1.0'
implementation 'com.android.support:preference-v7:25.1.0'
implementation 'com.android.support:recyclerview-v7:25.1.0'
implementation 'com.android.support:support-annotations:25.1.0'
implementation 'com.android.support:support-v4:25.1.0'
implementation 'com.android.support:cardview-v7:25.1.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
}
Top level build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
goto Android->sdk->build-tools directory make sure you have all the versions required . if not , download them . after that
goto File-->Settigs-->Build,Execution,Depoyment-->Gradle
choose use default gradle wapper (recommended)
and untick Offline work
gradle build finishes successfully for once you can change the settings
If it dosent simply solve the problem
check this link to find an appropriate support library revision
https://developer.android.com/topic/libraries/support-library/revisions
Make sure that the compile sdk and target version same as the support library version.
It is recommended maintain network connection atleast for the first time build (Remember to rebuild your project after doing this)
try this :
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
targetSdkVersion 26
}
}
compile 'com.android.support:appcompat-v7:25.1.0'
It has worked for me
I tried all of the above and nothing worked for me.
Then I followed Gradle Settings > Build Execution, Deployment > Gradle > Android Studio and checked "Disable embedded Maven repository".
Did a build with this checked and the problem was solved.
Just go to
File\Settings\Gradle. Deselect the "Offline work" box. Now you can connect and
download any necessary or missing dependencies
Your android studio may be forgot to put :
buildToolsVersion "26.0.0"
you need 'buildTools' to develop related design and java file. And if there is no any buildTools are installed in Android->sdk->build-tools directory then download first.
well got this answer from another site and don't want to take any credit for this but this solution works like butter.
Go to File\Settings\Gradle. Deselect the "Offline work" box. Now you can connect and download any necessary or missing dependencies.
This work for me. In the android\app\build.gradle file you need to specify the following
compileSdkVersion 26
buildToolsVersion "26.0.1"
and then find this
compile "com.android.support:appcompat-v7"
and make sure it says
compile "com.android.support:appcompat-v7:26.0.1"
OK It's A Wrong Approach But If You Use it Like This :
compile "com.android.support:appcompat-v7:+"
Android Studio Will Use The Last Version It Has.
In My Case Was 26.0.0alpha-1.
You Can See The Used Version In External Libraries (In The Project View).
I Tried Everything But Couldn't Use Anything Above 26.0.0alpha-1, It Seems My IP Is Blocked By Google. Any Idea? Comment
In my case, this error occur when i tried to use gridView
I resolved it by removing this line from build.grade(Module) file
implementation 'com.android.support:gridlayout-v7:28.0.0-alpha3'
This issue seems to like the following.
How to resolve repository certificate error in Gradle build
Below steps may help:
1. Add certificate to keystore-
Import some certifications into Android Studio JDK cacerts from Android Studio’s cacerts.
Android Studio’s cacerts may be located in
{your-home-directory}/.AndroidStudio3.0/system/tasks/cacerts
I used the following import command.
$ keytool -importkeystore -v -srckeystore {src cacerts} -destkeystore {dest cacerts}
2. Add modified cacert path to gradle.properties-
systemProp.javax.net.ssl.trustStore={your-android-studio-directory}\\jre\\jre\\lib\\security\\cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit
Ref : https://www.cresco.co.jp/blog/entry/2014//
Try to clear cache in android studio by
File-> Invalidate cache -> invalidate
after invalidating
build-> clean project
Then you can able to build the project
this work for me
compile 'com.android.support:appcompat-v7:26.0.0'
change 26.0.0 to 26.0.1
compile 'com.android.support:appcompat-v7:26.0.1'
this work for me. add configurations.all in app/build.gradle
android {
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
}