I receive following warnings when I sync Gradle in Android Studio 4.1.2 from stable channel :
Failed to resolve: legacy-support-v4-1.0.0
Failed to resolve: asynclayoutinflater-1.0.0
Failed to resolve: media-1.0.0
Failed to resolve: swiperefreshlayout-1.0.0
Failed to resolve: slidingpanelayout-1.0.0
Failed to resolve: legacy-support-core-ui-1.0.0
Here is my app module build.gradle file :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs.kotlin'
androidExtensions {
experimental = true
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.sample.android.storytel"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
buildConfigField "String", "STORYTEL_BASE_URL", "\"https://jsonplaceholder.typicode.com/\""
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Support libraries
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version_kotlin"
implementation "androidx.appcompat:appcompat:$version_support"
implementation "com.google.android.material:material:$version_material"
implementation "androidx.constraintlayout:constraintlayout:$version_constraint_layout"
implementation "androidx.palette:palette-ktx:$version_palette"
implementation "androidx.test.espresso:espresso-idling-resource:$version_espresso"
// Android KTX
implementation "androidx.core:core-ktx:$version_core"
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$version_navigation"
// Architecture components
implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions"
// Retrofit
implementation "com.squareup.retrofit2:retrofit:$version_retrofit"
implementation "com.squareup.retrofit2:converter-moshi:$version_retrofit"
implementation "com.squareup.retrofit2:adapter-rxjava2:$version_retrofit"
// Dagger
implementation "com.google.dagger:dagger:$version_dagger"
kapt "com.google.dagger:dagger-compiler:$version_dagger"
implementation "com.google.dagger:dagger-android:$version_dagger"
implementation "com.google.dagger:dagger-android-support:$version_dagger"
kapt "com.google.dagger:dagger-android-processor:$version_dagger"
// Network
implementation "com.squareup.okhttp3:logging-interceptor:$version_okhttp"
implementation "com.squareup.picasso:picasso:$version_picasso"
implementation "com.github.florent37:picassopalette:$version_picasso_palette"
// Moshi for parsing the JSON format
implementation "com.squareup.moshi:moshi:$version_moshi"
implementation "com.squareup.moshi:moshi-kotlin:$version_moshi"
//Android RX
implementation "io.reactivex.rxjava2:rxjava:$version_rxjava"
implementation "io.reactivex.rxjava2:rxandroid:$version_rxandroid"
// Timber
implementation "com.jakewharton.timber:timber:$version_timber"
// Dependencies for local unit tests
testImplementation "org.mockito:mockito-core:$version_mockito"
// Dependencies for Instrumentation tests
androidTestImplementation "androidx.test.ext:junit:$version_junit_ext"
// Espresso UI Testing
androidTestImplementation "androidx.test.espresso:espresso-core:$version_espresso"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$version_espresso"
// Testing Architecture components
testImplementation "androidx.arch.core:core-testing:$version_lifecycle_test"
// Android Testing Support Library's runner and rules
androidTestImplementation "androidx.test:runner:$version_runner"
androidTestImplementation "androidx.test:rules:$version_rules"
// AndroidX Test - JVM testing
testImplementation "androidx.fragment:fragment-testing:$version_fragment"
}
When I build the project, I receive following error :
Could not resolve asynclayoutinflater-1.0.0.aar (androidx.asynclayoutinflater:asynclayoutinflater:1.0.0)
Here you can find my project : https://github.com/Ali-Rezaei/Colors
Do you know why it happens and how to resolve it?
Addenda : I realized it is related to following dependency :
implementation "com.github.florent37:picassopalette:$version_picasso_palette"
Without this dependency, it works as expected.
The problem here is with
implementation "com.github.florent37:picassopalette:$version_picasso_palette"
is that this library is that it uses support library dependencies of android and you are trying to use it in a project where you are using jetpack library.
You can resolve it by
Using a version of that library which is migrated to JetPack..
OR
You can download the zip of that library and extract it and then open it as a project and then from refactor menu migrate to AndroidX then you import that custom project as a library into your project.
You live in a country that is under sanctions. You must use a filter breaker.
you can use this
Could not resolve asynclayoutinflater-1.0.0.aar (androidx.asynclayoutinflater:asynclayoutinflater:1.0.0)
This means gradle cannot find that dependency anywhere. Make sure that the library can be accessed by gradle inorder to resolve the problem.
Basically gradle is seeing your dependency as some unresolvable gibberish.
I am facing the following error after adding Google Photos to the gradle file. Firestore dependency is already added. Once I add google photos following error occurs. Kindly help.
ERROR: In project 'app' a resolved Google Play services library dependency depends on another at an exact version(e.g. "[1.10.
1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.
Dependency failing : io.grpc : grpc - auth : 1.10.1->io.grpc : grpc - core#[1.10.1], but grpc - core version was 1.16.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 io.grpc:grpc - core#1.16.1
--Project 'app' depends onto io.grpc:grpc - protobuf#1.10.1
--Project 'app' depends onto com.google.firebase:firebase - firestore#18.2.0
--Project 'app' depends onto io.grpc:grpc - auth#1.10.1
--Project 'app' depends onto io.grpc:grpc - protobuf - lite#1.16.1
--Project 'app' depends onto io.grpc:grpc - android#1.16.1
--Project 'app' depends onto io.grpc:grpc - okhttp#1.16.1
--Project 'app' depends onto com.google.api:gax - grpc#1.29.0
--Project 'app' depends onto com.google.photos.library:google - photos - library - client#1.1.0
--Project 'app' depends onto io.grpc:grpc - stub#1.16.1
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.
Build.gradle(Module : app)
apply plugin : 'com.android.application'
android{
compileSdkVersion 28
defaultConfig{
applicationId "com.savera.nammaflat"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes{
release{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies{
implementation 'com.android.support:support-v4:28.0.0'
/*https://stackoverflow.com/questions/55546885/google-api-client-android-and-firestore-is-giving-dexarchivemergerexception-buil*/
configurations{
all*.exclude module : 'guava-jdk5'
}
implementation fileTree(include: ['*.jar'], dir : 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('com.android.support:design:28.0.0')
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'
//Google sheets
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'pub.devrel:easypermissions:2.0.1'
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group : 'org.apache.httpcomponents'
exclude group : 'com.google.common.annotations'
}
// Google photos
implementation 'com.google.photos.library:google-photos-library-client:1.1.0'
// Firebase Authentication
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation('com.google.firebase:firebase-firestore:18.2.0') {
exclude group : 'com.google.common.annotations'
}
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
}
apply plugin : 'com.google.gms.google-services'
BUILD.gradle(PROJECT)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories{
google()
jcenter()
}
dependencies{
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects{
repositories{
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Could not solve this dependency conflict issue. Tried few ways but could not solve the issue. Instead of using
// Google photos
implementation 'com.google.photos.library:google-photos-library-client:1.1.0'
I used google photos rest api + volley. It is working fine.
I have been getting the following errors when I try to compile my project
ERROR: 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.
build.gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.spars.myapplication"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.razorpay:checkout:1.4.5'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.firebaseui:firebase-ui:3.3.1'
implementation 'com.android.support:cardview-v7:27.1.1'
testImplementation 'junit:junit:4.12'
//add start
implementation "android.arch.lifecycle:extensions:1.1.1"
// Multidex
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.firebase:firebase-analytics:16.3.0'
//add finish
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:23.3.0'
}
apply plugin: 'com.google.gms.google-services'
//added part xxx
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'
}
}
}
}
build.gradle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And I'm getting the following error
ERROR: 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#15.0.0
-- Project 'app' depends onto com.google.firebase:firebase-storage-common#15.0.0
-- Project 'app' depends onto com.google.firebase:firebase-common#16.0.4
-- Project 'app' depends onto com.google.android.gms:play-services-basement#16.0.1
-- Project 'app' depends onto com.firebaseui:firebase-ui-database#3.3.1
-- Project 'app' depends onto com.google.firebase:firebase-auth#15.0.0
-- Project 'app' depends onto com.google.android.gms:play-services-tasks#16.0.1
-- Project 'app' depends onto com.firebaseui:firebase-ui-auth#3.3.1
-- Project 'app' depends onto com.google.firebase:firebase-analytics-impl#16.3.0
-- Project 'app' depends onto com.google.firebase:firebase-analytics#16.3.0
-- Project 'app' depends onto com.firebaseui:firebase-ui-storage#3.3.1
-- Project 'app' depends onto com.firebaseui:firebase-ui-firestore#3.3.1
-- Project 'app' depends onto com.google.android.gms:play-services-auth-api-phone#15.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-api#16.3.0
-- Project 'app' depends onto com.google.android.gms:play-services-measurement-base#16.3.0
-- Project 'app' depends onto com.google.firebase:firebase-iid#17.0.3
-- Project 'app' depends onto com.google.android.gms:play-services-auth#15.0.0
-- Project 'app' depends onto com.google.android.gms:play-services-stats#16.0.1
-- Project 'app' depends onto com.firebaseui:firebase-ui#3.3.1
-- Project 'app' depends onto com.google.firebase:firebase-storage#15.0.0
-- Project 'app' depends onto com.google.android.gms:play-services-flags#15.0.1
-- Project 'app' depends onto com.google.firebase:firebase-database#16.0.6
-- Project 'app' depends onto com.google.android.gms:play-services-auth-base#15.0.0
-- Project 'app' depends onto com.google.android.gms:play-services-base#16.0.1
-- Project 'app' depends onto com.google.firebase:firebase-iid-interop#16.0.1
-- Project 'app' depends onto com.google.android.gms:play-services-ads-identifier#16.0.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.
Please help
The issue probably arises due to your Firebase UI version not being compatible with the versions of the other dependencies of Firebase you are using (the other ones require a higher Google Play Services version).
If you look here you will see which versions your Firebase UI will require.
Maybe you should consider updating your Firebase UI version, because the current one is 4.3.1
Import your dependencies as follows
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
import the following line too..
implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
implementation 'com.google.firebase:firebase-auth:17.6.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-messaging:19.0.0'
Update new possible answer for 2020, according to firebase document:
The Firebase Android library firebase-core is no longer needed. This
SDK included the Firebase SDK for Google Analytics.
Now, to use Analytics or any Firebase product that recommends the use
of Analytics (see table below), you need to explicitly add the
Analytics dependency: com.google.firebase:firebase-analytics:17.3.0.
That means, you should remove firebase-core
implementation 'com.google.firebase:firebase-core:16.0.3'
and add firebase analytics
implementation 'com.google.firebase:firebase-analytics:17.3.0'
Recently I have dived into learning new andoirdX artefacts including Android Architecture Components.
After reading through the officials docs and a google code samples I have successfully added the necessary dependencies in both my project and app level Gradle files.
They are as follows
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
and
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'
android {
compileSdkVersion 28
defaultConfig {
applicationId "_ _ _ _ _ _"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
implementation 'com.google.android.material:material:1.0.0-rc01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
def lifecycle_version = "2.0.0-beta01"
def room_version = "2.0.0-beta01"
def navigationVersion = '1.0.0-alpha06'
kapt "androidx.room:room-compiler:$room_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation 'androidx.core:core-ktx:1.0.0-alpha1'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
implementation "androidx.room:room-runtime:$room_version"
}
after giving Gradle sync everything worked fine, however, it showed an error saying "Manifest merge error please see logs for more info"
I have double checked with an app from google repository and everything seems normal.
Please accept my humble appreciation in advance
Recently I have run into the same issue, Before giving you the solution I would like to tell you that in recent days, due to fast-paced development tools offered by Google our days-old development technique has changed significantly.
Take jetpack as an example, which is a part of AndroidX, and adding it into your projects requires some necessary steps. Moreover, if you are like me who uses Android studio's dialogs for creating an app, you are likely to have these kinds of issues including the one you have mentioned.
The reason for this is android studio still use Appcompat-v7, androidX on the other hand, uses
androidx.appcompat:appcompat:1.0.0
see the full artifacts listing
Above all, after adding responsible dependencies you need to add these two lines in you gradle.properties file
android.useAndroidX=true
android.enableJetifier=true
Unfortunately, if have come this far you would still probably face
Manifest marge error
this is because your automated layout files still have old classpaths such as
android.support.design.widget.CoordinatorLayout
which should be like this androidx.constraintlayout.widget.ConstraintLayout
this one android.support.design.widget.AppBarLayout should be com.google.android.material.appbar.AppBarLayout and So on.
After rechecking every classpath rebuild your project and everything should be fine.
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'