Android studio默认项目失败:错误:无法解决:com.android.support:support-v4:25.2.0

时间:2017-06-21 02:14:58

标签: android android-studio android-sdk-tools

我实际上只是第一次启动应用程序开发,而我创建新项目时的默认项目将无法构建。我曾尝试在Google和SO上查找这些错误并找到了一些,但他们的解决方案无效。鉴于我根本没有编辑过这些文件,我认为Android Studio没有正确设置是一个问题,但无法弄清楚。错误如下:

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

它指向的build.gradle文件如下:

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'
}

我尝试过以前的项目,我创建了一些我在网上找到的东西。比如他们曾建议版本中的+可能导致不可预测的构建,但事实并非如此。一个人在dependencies部分推荐了一些编译行,它改变了错误片刻说我需要下载一些东西,然后我就回到了原来的错误。我也试图确保SDK工具更新,它们似乎是。任何建议将不胜感激。

3 个答案:

答案 0 :(得分:17)

请注意,从revision 25.4.0到最新的支持库,我们需要添加google maven。与release note says中一样:

  

重要提示:支持库现在可以通过Google获得   Maven存储库。您无需下载支持存储库   来自SDK Manager。有关更多信息,请参阅支持库设置。

所以你需要将google maven添加到 root build.gradle中,如下所示:

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

Support Library Setup了解详情。

答案 1 :(得分:2)

试试这个:

  1. 在Android Studio中,打开工具 - > Android - > SDK Manager
  2. 在标签" SDK工具"取消检查导致问题的库
  3. 点击"申请"卸载它们
  4. 重新检查相同的库点击"申请"重新安装它们
  5. 关闭SDK Manager并运行Gradle sync / build

答案 2 :(得分:0)

我遇到了同样的问题,这是由于对另一个图书馆的干扰造成的 在我的情况下,我不得不评论:

编译' com.onesignal:OneSignal:[3.5.3,4.0.0)

现在建立