Gradle build error: Failed to resolve: - android

I just downloaded Android Studio and created a new project and I'm getting gradle build errors:
Failed to resolve: com.android.support.test.espresso-core:2.2.2
and
Failed to resolve: com.android.support.appcompat-v7:25.3.1
This error was resolved reinstalling the SDK Tools + Repository + API when launching android studio as admin.
I've installed API Level 25 which what I want to build on and have downloaded the SDK Build-Tools. I have also already download the support repository
Here's my app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.jtsalas.mirrorcontrol"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

From the SDK manager, make sure you have both the Android Support Repository and Google Repository installed and up to date. You should then be able to find the relevant artifacts in sub folders of your /extras/android/m2repository directory

From your error it seems that you are not including espresso libraries. The solution to this is adding espresso core library which is part Android Testing support library which is hosted in the google's Maven repository think this as kind of git repository but for dependencies.
So we tell the gradle build system to look in the Maven repository for dependencies by specifying its URL.
This is done by adding Maven url in the application level build.gradle file under repositories block
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
and in the module level build.gradle file mention the dependencies that you want from the maven repository by mention their name as follows:
dependencies{
//other dependencies go here
//testing dependencies
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
}
That is the reason for including Maven repository url in the app level build.gradle file, hope this helps.

In project.gradle file, the allprojects root align this way:
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
jitpack is used as the dependency for multiple libraries, if you're not using any sort of library that don't requires it then not include maven line.

Well, I don't know the perfect answer but..... how about comparing with my SDK Tools?

I solved it by uninstalling Android Studios and deleting old versions of Android Studios in my C:\Users[Username] and reinstalled Android Studio as administrator.

It seems like you updated android studio and opening previous project in it.The simplest way is create new project and copy
1. compileSdkVersion 26
2. buildToolsVersion "26.0.1"
3. targetSdkVersion 26
4. compile 'com.android.support:appcompat-v7:26.+'
and paste them in appropriate places in app level build gradle.
it will ask to update to take advantages .. allow it to update.
best luck ... It worked for me.

if your project is Flutter,
clean project [by 'flutter clean' command]
In project.gradle file add [ google() ]
in Android studio: File Menu -> Invalidate...
project.gradle:
allprojects {
repositories {
google()
jcenter()
}
}

Related

Build errors after Android Studio 3.2.1 upgrade

I am building a sample project from Udacity. This was working fine till now, but after upgrading to Android Studio 3.2.1, I am facing the build error below.
Gradle version: 4.6
Project link: https://github.com/udacity/ud851-Sunshine/tree/student/S02.02-Solution-Menus
Could not find com.android.tools.build:aapt2:3.2.1-4818971**. Searched in the following locations:
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar Required by:
project :app
How can I fix it?
For Android Studio 3.2.1 update
Just add google() in root level build.gradle
buildscript {
repositories {
google() // <--here
jcenter()
}
}
allprojects {
repositories {
google() // <-- here
jcenter()
}
}
and see the magic - error is gone.
The project gradle version is pretty old:
classpath 'com.android.tools.build:gradle:2.2.3'
And you are using Android Studio v3.2.1 so, update the gradle:
classpath 'com.android.tools.build:gradle:3.2.0' // or 3.2.1 maybe
Also, as you can see, it was looking for some packages in :
file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
Which means you probably forgot to add google() as the top level repository. Just add google()
to your repositories in your root build.gradle.
To get this solved
Firstly download the missing Jar file from the link below. I see you are missing version 3.2.1-4818971
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
Switch your folder structure from Android to Project.
Now navigate to the libs folder inside the app - build folder. (If the libs folder does not exist, you can create it by right clicking on the app folder - select New - select Directory.)
Paste the downloaded.jar file inside libs folder. Right click on the jar file and at the bottom click on Add as library. This will take care of adding implementation files('libs/library_name.jar') in build.gradle [You don't have to manually enter this in your build file].
Everything should be okay once you sync after doing the above.
Here is the source link to this solution: https://developer.android.com/studio/command-line/aapt2#download_aapt2
Let me know if you run into any other issues whilst doing the above.
Yeah, as d4rkcon said download https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
But you can do simplier - just put this file in directory where Andoid Studio is trying to find it. If you don't have directories like /tools/build/aapt2/3.2.1-4818971/ in AndroidSDK folder just create them and then put aapt2-3.2.1-4818971-windows.jar file in.
Add Google repository in your build.gradle(Project:xxxxx)
allprojects {
repositories {
google()
}
}
clear gradle cache
rm -rf $HOME/.gradle/caches/
and resync to download all dependencies
Change your build.gradle as follows.
android {
compileSdkVersion 26
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "your package name here"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:26.1.0'
}
add google() on your build script > repositories
add google on allprojects > repositories
use implementation as replacement of compile keyword,
also on your filetree.
EX.
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:25.3.1'
implementation 'com.android.support:design:25.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:25.3.1'
For Android Studio 3.6.3 update : just adding google maven tag in buildscript and all projects repositories in build.gradle file of project file solves the issue.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Error: Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:27.1.1 [duplicate]

I have searched around a lot but I cannot really find a post that helps I am somewhat new to android so some of this goes over my head. Anyway, my problems started when I got an error saying gradle plugin was old and the sync would not complete. So I changed a few things around not really sure what I did. Now I have:
Error(25,13) Failed to resolve: com.android.support:appcompat-v7 24.0.1
Project gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.bisesifreelance.maxbisesi.tic_tac_toe"
minSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.0.1'
testCompile 'junit:junit:4.12'
}
Also I have installed all build tools in SDK manager I'm not allowed to embed images yet? but it says:
Android SDK Plaform-Tools 24.03 installed
Android SDK Tools 25.2.2 installed
Thank YOu! I'm very lost.
You can also write like this:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
try
compile 'com.android.support:appcompat-v7:24.2.1'
EDIT
For sdk 27
buildToolsVersion "27.0.3"
implementation "com.android.support:appcompat-v7:27.1.1"
Try adding jcenter like this way
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
Rather than
repositories {
jcenter()
}
Make sure that this folder exists:
\your-android-sdk\extras\android\m2repository\com\android\support\appcompat-v7\24.0.1
Of course, 24.0.1 should be replaced by the latest version.
I had this problem because I occasionally renamed 24.0.1 to something else and so the required folder couldn't be found.
I had the same problem after updating Android Studio. In my case it was an issue of permissions as I do my day-to-day programming on my user account, while Android studio was installed and updated with the administrator account.
FIX:
Open the standalone SDK manager and go down to 'extras'. Click on 'Android Support Repository' (which will probably set as 'Not installed') and install the packages. If you are prompted with an error message saying something like 'error trying to rename folder'. Go to the folder that is mentioned in the message and make sure that the permissions are set correctly. After that click 'Try Again' and it should install the package without a problem.
NOTE: This might happen a few more times. Just repeat the process for each file. The problem should then be solved.
Change a character - to :
compile 'com.android.support:appcompat-v7:24.2.1'
rather than
compile 'com.android.support:appcompat-v7-24.2.1'
try update the IDE and remove earlier build version (like 23) after installing later one and rename it to newer one.
Open SDK Manager and update the Extras-->Android Support Repository.
Path ..sdk\extras\android\m2repository\com\android\support\appcompat-v7>
Check for the updated version being installed.
In build.gradle in all projects, add Marvel and add this URL 'https://maven.google.com'

Failed to resolve: com.android.support:appcompat-v7 24.0.1

I have searched around a lot but I cannot really find a post that helps I am somewhat new to android so some of this goes over my head. Anyway, my problems started when I got an error saying gradle plugin was old and the sync would not complete. So I changed a few things around not really sure what I did. Now I have:
Error(25,13) Failed to resolve: com.android.support:appcompat-v7 24.0.1
Project gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.bisesifreelance.maxbisesi.tic_tac_toe"
minSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.0.1'
testCompile 'junit:junit:4.12'
}
Also I have installed all build tools in SDK manager I'm not allowed to embed images yet? but it says:
Android SDK Plaform-Tools 24.03 installed
Android SDK Tools 25.2.2 installed
Thank YOu! I'm very lost.
You can also write like this:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
try
compile 'com.android.support:appcompat-v7:24.2.1'
EDIT
For sdk 27
buildToolsVersion "27.0.3"
implementation "com.android.support:appcompat-v7:27.1.1"
Try adding jcenter like this way
repositories {
jcenter {
url "http://jcenter.bintray.com/"
}
}
Rather than
repositories {
jcenter()
}
Make sure that this folder exists:
\your-android-sdk\extras\android\m2repository\com\android\support\appcompat-v7\24.0.1
Of course, 24.0.1 should be replaced by the latest version.
I had this problem because I occasionally renamed 24.0.1 to something else and so the required folder couldn't be found.
I had the same problem after updating Android Studio. In my case it was an issue of permissions as I do my day-to-day programming on my user account, while Android studio was installed and updated with the administrator account.
FIX:
Open the standalone SDK manager and go down to 'extras'. Click on 'Android Support Repository' (which will probably set as 'Not installed') and install the packages. If you are prompted with an error message saying something like 'error trying to rename folder'. Go to the folder that is mentioned in the message and make sure that the permissions are set correctly. After that click 'Try Again' and it should install the package without a problem.
NOTE: This might happen a few more times. Just repeat the process for each file. The problem should then be solved.
Change a character - to :
compile 'com.android.support:appcompat-v7:24.2.1'
rather than
compile 'com.android.support:appcompat-v7-24.2.1'
try update the IDE and remove earlier build version (like 23) after installing later one and rename it to newer one.
Open SDK Manager and update the Extras-->Android Support Repository.
Path ..sdk\extras\android\m2repository\com\android\support\appcompat-v7>
Check for the updated version being installed.
In build.gradle in all projects, add Marvel and add this URL 'https://maven.google.com'

Android Build Gradle doesn't complete

I had a problem to run android-studios build gradle, so I tested many solution but unfortunately I couldn't solve my problem:
Now i uninstall my old Android studio and Android-sdk , then I download android studio 1.5.1 that contains default SDK .
I install them and I create an empty project , But it take 30 minutes to build project, I will add dialog window that shown in this period of time .
Finally project created with this error :
Error:(23, 17) Failed to resolve: junit:junit:4.12
Could any one help me ,please ?
build.gradle file content:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.armangar.app.fortest"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
top build.gradle file content:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
testCompile is the configuration for unit tests (located in src/test) and androidTestCompile is used for the test api (located in src/androidTest).
The main distinction between the two is that test runs in a regular Java JVM, and androidTest tests run on an Android device (or an emulator).
So, use
testCompile 'junit:junit:4.12'
instead of
androidTestCompile 'junit:junit:4.12'
source: http://tools.android.com/tech-docs/unit-testing-support
I think you have SSL problem.
Try by replacing
jcenter { url 'http://jcenter.bintray.com' }
with
jcenter()
in both repository blocks in build.gradle file and try to build gradle again.
I change jcenter() to mavenCentral() in build.gradle .
So my problem solved
EDIT:
This issue was related to my proxy . So I could not download from jcenter().
If you have a problem same this one, please check your Internet proxy .

Android Studio could not find any version that matches com.android.support:appcompat-v7:+

Running a project in Android Studio fails with this error: could not find any version that matches com.android.support:appcompat-v7:+
How can I fix this error?
From Android Studio go to:
Tools >> Android >> SDK Manager
Select and install "Extras|Android Support Repository"
For me it worked after changing the version from 7:27.+ to 7:+
In Project > app > build.gradle file replace the line
implementation 'com.android.support:appcompat-v7:+'29.+'
with
implementation 'com.android.support:appcompat-v7:+'
and line
implementation 'com.android.support:design:29.+'
with
implementation 'com.android.support:design:+'
Then clean build
Also as as said on How to update Android platform-tools in a headless linux?
android list sdk
android update sdk --no-ui --filter extra
It is very simple.
Kindly update and replace the below code in build.gradle(Project :App Name).
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
After installing Extras|Android Support Repository, It does not work for me. Then I change v7:1.6 to v7:1.8 in the app build.gradle file.
com.android.support:appcompat-v7:1.8.+! and It works for me.
Open SDK Manager.exe in your Android Studio folder and install a matching API.
I found all these answers incorrect for me. Instead in your android studio look below on the left. There will be some help for this.
For example, you will notice
This support library should not use a different version (32) than the compilesdkVersion (23)
Then you change the version of to 23 like this
compile 'com.android.support:support-v4:23'
Now, you will see a message
A newer version of com.android.support-v4 than 23 is available 23.4.0.
Thats how I knew that the correct version is 23.4.0
If you see this after you've just created a new project in Intellij then try to recreate it again with "Use AndroidX artifacts" checked
To whom came here for same error but version 29, change your support library to version 28:
build.gradle(app):
dependencies {
...
implementation 'com.android.support:appcompat-v7:28.+'
...
}
None of googled solutions worked for me. Then I saw Android has only support library up to version 28. It is weird that I got this error in an out-of-box created Android Studio project.
I'm not sure which Android Studio version was, cause I upgraded Studio after got error. Now in Android Studio 3.6.3, new projects coming with 'androidx.appcompat:appcompat:1.0.2'.
This worked for me to build and run this project.
I had to add google in both sections.
build.gradle (project)
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
build.gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "29.0.2" //25.0.2"
defaultConfig {
applicationId 'com.github.nkzawa.socketio.androidchat'
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
////noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:25.0.+'
////noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:25.0.+'
implementation ('io.socket:socket.io-client:0.8.3') {
exclude group: 'org.json', module: 'json'
}
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'junit:junit:4.12'
}
Got the same error but version 26.
Downloading the libraries through the SDK Manager is no longer supported. The support libraries are now available through Google's Maven repository.
Solution:
In build.gradle (project) inside both buildscript/repositories and allprojects/repositories add this:
maven {
url 'https://maven.google.com/'
name 'Google'
}
Result:
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
It worked for me.

Categories

Resources