Gradle同步时出现"Failed to resolve: com.android.support:support-v4:26.0.0"和其他类似错误

46

我刚刚为Android手机和手表创建了一个新的Android Studio项目。最初的gradle构建失败,因为我遇到了几个错误-

Error: Failed to resolve: com.android.support:support-v4:26.0.0

Error: Failed to resolve: com.android.support:percent:26.0.0

Error: Failed to resolve: com.android.support:recyclerview-v7:26.0.0

Error: Failed to resolve: com.android.support:support-annotations:26.0.0

每次出现错误时,我都有选项安装仓库并同步项目,但当我点击它时,没有任何反应。我已经花费了几个小时来尝试找到为什么会出现这些错误,但是我找不到任何解决方案。有人知道如何解决这些非常令人沮丧的错误吗?谢谢!

build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

    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()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle (移动端)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.georgeberdovskiy.androidweartest"
        minSdkVersion 23
        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'
    })
    wearApp project(':wear')
    compile 'com.google.android.gms:play-services-wearable:11.0.4'
    compile 'com.android.support:appcompat-v7:26+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile "com.android.support:support-core-utils:26+"
    testCompile 'junit:junit:4.12'
}

build.gradle(wear)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.georgeberdovskiy.androidweartest"
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    provided 'com.google.android.wearable:wearable:2.0.4'
    compile 'com.google.android.support:wearable:2.0.4'
    compile 'com.google.android.gms:play-services-wearable:11.0.4'
    compile "com.android.support:support-core-utils:26+"
}

我确信我的Android Studio版本已经更新,并且所有支持库和API都已安装。

输入图像描述

我注意到这些错误只出现在wear build.gradle中... - George B
  1. 将您的buildToolsVersion "26.0.1"更改为buildToolsVersion "26.0.0"
  2. 将依赖项版本从 compile 'com.android.support:recyclerview-v7:26.0.0' 更改为 compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
希望这能帮到您。
- Madhan
更改构建版本将起作用,如果您在此过程中遇到任何困难,请告诉我。 - Madhan
有关IONIC 3的解决方案,请查看此链接--> https://www.freakyjolly.com/ionic-3-resolve-execution-failed-for-task-appprocessdebugresources/ - Code Spy
10个回答

78

我没有一个Android Wear项目,但是当我想要将现有项目的Support Library版本升级到26.0.0时,遇到了同样的问题。自从26.0.0版本起,支持库可以通过Google的Maven存储库获得。因此,我需要在我的build.gradle文件中添加该存储库。

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

查看https://developer.android.com/topic/libraries/support-library/setup.html获取更多详细信息。


从Maven到JCenter再回到Maven... 真是令人困扰。 - Kenny Worden

11
以下方法对我有用: 在应用程序的 build.gradle 文件中,考虑添加以下内容:
allprojects {
repositories {
    maven {
        url "https://maven.google.com"
    }
}
}

在 Module build.gradle 文件中:

compileSdkVersion 26
buildToolsVersion "26.0.1"

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-wearable:11.0.4'
compile 'com.android.support:support-compat:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-annotations:26.0.1'
compile 'com.android.support:support-vector-drawable:26.0.1'
compile 'com.android.support:animated-vector-drawable:26.0.1'
compile 'com.android.support:design:26.0.1'
compile 'com.android.support:support-v13:26.0.1'
compile 'com.android.support:percent:26.0.1'
compile 'com.android.support:wear:26.0.1'
compile 'com.google.android.support:wearable:2.0.4'
provided 'com.google.android.wearable:wearable:2.0.4'
}

最终我使用 IMPLEMENTATION 更新了依赖项,而不是 COMPILE。我仍然无法将 gms:play-services:11.6.2 拆分为单个模块,这让我陷入了灾难中,摧毁了一切。我已经与它战斗了五个晚上,最终放弃并加载整个包。 - Parkbrakereminder
尝试使用相同的com.android.support版本。 - Khurshid Ansari

5

要么将您的构建工具版本从26.0.1更改为26.0.0,或者您可以像下面这样将26.0.0替换为26.+

compile 'com.android.support:support-v4:26.0.0'

to

compile 'com.android.support:support-v4:26.+"

将所有内容同样处理......希望这有所帮助。编码愉快!^_^


还是不行,仍然出现相同的错误。 - George B
你现在是在WIFI上还是离线状态?请确保需要联网。 - Arjun Katwal
是的,我已连接到 WiFi。 - George B
@GeorgeB 要么在每个代码中添加 '26+1',要么将您的构建工具版本从 '26.0.1' 改为 '26.0.0' 并进行同步。我在我的工作空间中测试过了,它完美地运行了。 - Arjun Katwal

3

请将此替换为:

    compile 'com.android.support:recyclerview-v7:26.0.0'

使用此功能

    compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'

同样的操作适用于所有项目

更新 - 新版本已发布

    compile 'com.android.support:recyclerview-v7:26.1.0'

3

现在,我通过更改 wear build.gradle 文件来解决这个问题:

compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'

看起来问题出在 com.google.android.support:wearable:2.0.4 上。使用 26.0.1 的构建工具可以正常编译。虽然我还没有深入研究,但这似乎是一个与存储库相关的依赖问题,不过这只是根据错误信息的猜测。


谢谢@John Smith。这对我很有帮助 :) - TutorialsBee

3
请在您的app/build.gradle中添加以下依赖项。
repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven{url 'https://maven.google.com'}
}

2
请在您的gradle中添加以下依赖项。 替换:
    compile 'com.android.support:support-v4:26.0.0'

使用

   compile 'com.android.support:support-v4:25.0.0'

替换操作

   compile 'com.android.support:appcompat-v7:26+'

使用

compile 'com.android.support:appcompat-v7:25.0.0'

1
没起作用,现在我得到了另一个错误,除了其他的错误之外 - Error:(30, 13) Failed to resolve: com.android.support:support-v4:26.0.0 - George B

1
这个对我有效。
allprojects {
    repositories {
        jcenter()
        google()
    }
}

google()通过以下配置实现了魔法

Studio版本:3.0 beta 2

classpath 'com.android.tools.build:gradle:3.0.0-beta2'

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip

1
我的项目出现这些错误的原因是我为Android平台26创建了该项目。然而,Wear目前不支持26,必须在build.gradle的wear模块中更改targetcompile SDK版本为25。

Android开发者文档链接 - https://developer.android.com/training/wearables/apps/creating.html#setting-up-a-phone

build.gradle(wear)

apply plugin: 'com.android.application'


android {
compileSdkVersion 25
buildToolsVersion "26.0.1"

defaultConfig {
    applicationId "com.georgeberdovskiy.findmyphone"
    minSdkVersion 25
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),       'proguard-rules.pro'
    }
    }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.android.gms:play-services-wearable:11.0.4'

}

apply plugin: 'com.google.gms.google-services'

我只需要将wear模块的编译和目标SDK版本更改为25。对于移动模块,我将它们保留在26。


1
为了获得最佳结果,您应该确保使用与compileSdkVersion(在本例中为25.X.X)具有相同主版本号的buildToolVersion。 - TofferJ
使用 Build Tools 26.0.1 对我来说非常有效。虽然感谢您的建议。 - George B

0

我遇到了这个问题,更改构建工具/ SDK 版本没有起作用,明确编译版本也没有起作用,离线构建也没有起作用。

最后我只是改变了可穿戴设备的版本,这个问题就解决了。

provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'

provided 'com.google.android.wearable:wearable:2.0.2'
compile 'com.google.android.support:wearable:2.0.2'

顺便说一下,我现在使用离线构建,因为当我检查这个问题时,它真的非常快。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,