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

"Failed to resolve: com.android.support:support-v4:26.0.0" and other similar errors on Gradle sync

我刚刚为 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

对于每个错误,我都可以选择 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。

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

将您的构建工具版本从 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.+"

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

替换为:

    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'

现在,我通过改变磨损来解决这个问题 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 构建工具就可以正常编译了。我没有进一步研究这个问题,但它看起来像是与存储库相关的依赖性问题,尽管这实际上只是错误消息的猜测。

我的项目给我这些错误的原因是因为我为 Android 平台 26 创建了项目。但是,Wear 目前不支持 26,必须更改 targetcompile SDK 版本到 build.gradle.

磨损模块中的 25

Link 到 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'

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

以下对我有用:

在申请中 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'
}

遇到这个问题,改build tool/sdk版本不行,明明写编译版本不行,离线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'

顺便说一句,我现在用的是离线构建,因为我检查这个问题的时候真的很快。

我没有 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 了解更多详情。

在您的 app/build.gradle.

中添加以下依赖项
repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven{url 'https://maven.google.com'}
}

这个对我有用

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