Gradle build error: Failed to resolve:

隐身守侯 提交于 2019-12-04 07:39:45

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!