Manifest marge error after migrating to androidX - android

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.

Related

Android studio build fails

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.

Problem in integrating 'com.google.gms.google-services' plugin with android app

When I'm trying to put apply plugin: 'com.google.gms.google-services' at the bottom of my build gradle or anywhere else inside my apps build gradle I get the following error:
In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[19.0.
2]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.
Dependency failing: com.google.android.gms:play-services-vision-image-label:18.0.3 -> com.google.android.gms:play-servic
es-vision-common#[19.0.2], but play-services-vision-common version was 19.1.0.
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-ml-vision-object-detection-model#{strictly 19.0.5}
-- Project 'app' depends onto com.google.android.gms:play-services-vision-common#{strictly 19.1.0}
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision#{strictly 24.0.3}
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision-internal-vkp#{strictly 17.0.1}
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision-object-detection-model#19.0.5
-- Project 'app' depends onto com.google.firebase:firebase-ml-vision#24.0.3
-- Project 'app' depends onto com.google.android.gms:play-services-vision-image-label#{strictly 18.0.3}
-- Project 'app' depends onto com.google.android.gms:play-services-mlkit-face-detection#16.1.0
-- Project 'app' depends onto com.google.android.gms:play-services-vision#{strictly 20.1.0}
-- Project 'app' depends onto com.google.android.gms:play-services-mlkit-face-detection#{strictly 16.1.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.
My build.gradle at app level is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.mlkitfacedetection"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.gms:play-services-mlkit-face-detection:16.1.0'
implementation 'com.google.firebase:firebase-ml-vision:24.0.3'
implementation 'com.google.firebase:firebase-ml-vision-object-detection-model:19.0.5'
def camerax_version = "1.0.0-beta03"
// CameraX core library using camera2 implementation
implementation "androidx.camera:camera-camera2:$camerax_version"
// CameraX Lifecycle Library
implementation "androidx.camera:camera-lifecycle:$camerax_version"
// CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha10"
}
apply plugin: 'com.google.gms.google-services'
I am unable to resolve the error. The same code in another app is working absolutely fine.
I am using google-serivices.json file from another app registered on firebase. Isn't it the cause of problem?
I tested this workaround and this seems to work. Add the following in your dependencies block:
implementation 'com.google.android.gms:play-services-vision-image-label:18.0.4'
implementation 'com.google.android.gms:play-services-vision:20.1.1'
implementation 'com.google.android.gms:play-services-vision-common:19.1.1'
implementation "com.google.android.gms:play-services-vision-face-contour-internal:16.0.2"
implementation 'com.google.android.gms:play-services-vision-image-label:18.0.5'
implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
implementation 'com.google.firebase:firebase-ml-vision-face-model:20.0.2'
implementation 'com.google.firebase:firebase-ml-model-interpreter:22.0.4'
implementation 'org.tensorflow:tensorflow-lite:2.0.0'
Follow this link for more detail-
https://github.com/firebase/firebase-android-sdk/issues/1904
You may just have to update your dependencies: File-->Project Structures-->Dependencies Then in the lower part you will see any dependencies that need updating...Worked for me

androidx migration problem with several libraries

I have migrated to androidx recently and faced these problems.
Problem :
My configuration
build.gradle(app) :
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.crazy.tuhin.aroundme"
minSdkVersion 16
targetSdkVersion 28
versionCode 5
versionName "1.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.annotation:annotation:1.1.0'
//google
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
}
build.gradle(project) :
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
// 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 :
#Fri Apr 10 02:21:34 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
settings.gradle :
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true
My android studio version :
Android Studio 3.6.2
My question is do I have to change every import manually? but I have this android.enableJetifier=true
Can you please point out the problem? The already mentioned problems and solutions here are not helping.
Thanks.
My question is do I have to change every import manually?
Yes, you've to.
android.enableJetifier=true helps migrate third-party dependencies to use AndroidX. Jetifier will change the byte code of those dependencies to make them compatible with projects using AndroidX.
Following are the proper steps to migrate -
Preparing to migrate
Before you start to migrate to AndroidX you should:
Create a new branch on which to make the migration changes.
If possible, suspend or minimize development ( at least don’t try to do refactoring or pull in new features ) during the migration, as this will help reduce the number of merge conflicts that could happen.
Migrate
Throughout the migration steps focus on addressing errors, getting your app to compile, and passing all tests.
Step 1:
Migrating directly to AndroidX from an older version of the Support Library, say 26 or 27, isn’t recommended. Bring the app up to date. Update the project to use the final version of the support library: version 28.0.0. This is because AndroidX artifacts with version 1.0.0 are binary equivalent to the Support Library 28.0.0 artifacts. Then address all of the API changes, and ensure your app compiles with version 28.
Step 2:
Update third-party dependencies to the latest. Not doing so could result in unexplained compilation errors.
Step 3:
Enable the following flags in gradle.properties. With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.
android.enableJetifier=true - Jetifier helps migrate third-party dependencies to use AndroidX. Jetifier will change the byte code of those dependencies to make them compatible with projects using AndroidX.
android.useAndroidX=true - The Android plugin uses the appropriate AndroidX library instead of a Support Library.
SOLVED
If you run into an unfortunate problem like mine, do these:
1. Delete all unused imports (grey coloured) from every class.
2. Now import the required classes like this :
3. Repeat for every related class.

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

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'

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.

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'

Categories

Resources