【问题标题】:"Failed to resolve: com.android.support:support-v4:26.0.0" and other similar errors on Gradle sync [duplicate]“无法解决:com.android.support:support-v4:26.0.0”和 Gradle 同步上的其他类似错误 [重复]
【发布时间】:2018-01-05 05:08:43
【问题描述】:

我刚刚为 Android Mobile Wear 创建了一个新的 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

对于每个错误,我都可以选择Install repository and sync project,但是当我单击它时没有任何反应。我花了几个小时试图找出为什么会出现这些错误,但我找不到任何解决方案。有人知道如何解决这些非常令人沮丧的错误吗?谢谢!

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(磨损)

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 都已安装。

【问题讨论】:

  • 我注意到这些错误仅适用于磨损 build.gradle...
  • 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' 希望这对你有帮助。
  • 更改构建版本将起作用,如果您发现任何困难,请告诉我
  • 对于 IONIC 3 在这里检查解决方案 --> freakyjolly.com/…

标签: java android gradle compiler-errors wear-os


【解决方案1】:

我没有 Android Wear 项目,但是当我想将现有项目的支持库版本升级到 26.0.0 时,我遇到了同样的问题。自 26.0.0 起,支持库可通过 Google 的 Maven 存储库获得。所以我不得不将存储库添加到我的构建中。 gradle 文件。

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

查看https://developer.android.com/topic/libraries/support-library/setup.html了解更多详情。

【讨论】:

  • Wtf。从 Maven 到 JCenter 再到 Maven...
【解决方案2】:

以下内容对我有用:

在Application build.gradle 中考虑添加以下内容:

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

在模块 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'
}

【讨论】:

  • 最后我用 IMPLEMETATION 而不是 COMPILE 更新了依赖关系。我仍然无法将 gms:play-services:11.6.2 拆分为单个模块,我需要。它通过摧毁一切将我带入灾难,我正在为第五个夜晚而战,最终放弃并加载整个包裹。
  • 试试 com.android.support 版本应该一样。
【解决方案3】:

要么将您的构建工具版本从 26.0.1 更改为 26.0.0,要么您可以将 26.0.0 替换为 26.+,如下所示。

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

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

对所有人都做同样的事情... 希望能帮助到你。 快乐编码! ^_^

【讨论】:

  • 没有用,仍然出现同样的错误。
  • 你是在WIFI还是离线?确保它需要互联网连接。
  • 是的,我已连接到 WiFi。
  • @GeorgeB 在每个代码中添加'26+1' 或从'26.0.1' 制作您的构建工具版本'26.0.0' 并同步它。我在我的工作空间进行了测试,效果很好。
【解决方案4】:

目前,我通过更改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。它对我有帮助:)
【解决方案5】:

在您的app/build.gradle 中添加以下依赖项。

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven{url 'https://maven.google.com'}
}

【讨论】:

    【解决方案6】:

    替换这个:

        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'
    

    【讨论】:

      【解决方案7】:

      在你的 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'
      

      【讨论】:

      • 没用,现在我在其他错误之上又遇到了另一个错误 - Error:(30, 13) Failed to resolve: com.android.support:support-v4:26.0.0
      【解决方案8】:

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

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

      build.gradle(磨损)

      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 用于移动模块。

      【讨论】:

      • 您应该确保使用与 compileSdkVersion(在本例中为 25.X.X)具有相同主要版本号的 buildToolVersion 以获得最佳结果。
      • 使用构建工具 26.0.1 对我来说效果很好。不过还是谢谢你的建议。
      【解决方案9】:

      这个对我有用

      allprojects {
          repositories {
              jcenter()
              google()
          }
      }
      

      google() 通过以下配置发挥神奇作用

      工作室版本: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
      

      【讨论】:

        【解决方案10】:

        遇到这个问题,改build tool/sdk版本不行,明明写compile版本不行,离线build不行。

        最后我只是换了可穿戴版本,这个问题就解决了。

        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'
        

        顺便说一句,我现在使用离线构建,因为我检查这个问题时确实很快。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-01-16
          • 2023-03-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多