Android studio default project fails: Error:Failed to resolve: com.android.support:support-v4:25.2.0

怎甘沉沦 提交于 2019-11-26 23:31:08

问题


I am literally just starting app development for the first time and the default project when I create a new one will not build. I have tried looking on Google and SO for these errors and have found some but their solutions do not work. Given that I have not edited the files at all, I presume it is an issue with Android Studio not being setup properly but can't figure it out. The errors are as follows:

Error:Failed to resolve: com.android.support:support-v4:25.2.0
Install Repository and sync project
Open File
Show in Project Structure dialog

Error:(23, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:2.2.2
Install Repository and sync project
Show in File
Show in Project Structure dialog

Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:26.+
Install Repository and sync project
Show in File
Show in Project Structure dialog

The build.gradle file it points to is as follows:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.extremecomputing.spotzz"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    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:26.+'
    compile 'com.google.android.gms:play-services-maps:11.0.1'
    testCompile 'junit:junit:4.12'
}

I have tried with a previous project that I had created a few things I found online. Such as they had recommended the + in the version could cause unpredictable builds, but that wasn't it. One had recommended a few compile lines in the dependencies section, it changed the errors for a moment saying I needed to download something, I did then it went back to the original errors. I also have tried to make sure that the SDK tools are updated, and they appear to be. Any suggestions would be greatly appreciated.


回答1:


Try this:

  1. in Android Studio, open Tools -> Android -> SDK Manager
  2. under tab "SDK Tools" un-check the libraries causing problems
  3. click "apply" to uninstall them
  4. re-check the same libraries click "apply" to reinstall them
  5. close SDK Manager and run Gradle sync / build



回答2:


Please be noted that support library from revision 25.4.0 to the latest, we need to add google maven. As in the release note says:

Important: The support libraries are now available through Google's Maven repository. You do not need to download the support repository from the SDK Manager. For more information, see Support Library Setup.

So you need to add the google maven to your root build.gradle like this:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Read more at Support Library Setup.




回答3:


I had the same problem and it was due of an interference with another library.
In my case I had to comment:

compile 'com.onesignal:OneSignal:[3.5.3,4.0.0)

Now it builds



来源:https://stackoverflow.com/questions/44665809/android-studio-default-project-fails-errorfailed-to-resolve-com-android-suppo

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