“无法解决:com.android.support:support-v4:26.0.0”以及 Gradle 同步上的其他类似错误

2022-08-31 23:51:26

我刚刚为Android Mobilewear创建了一个新的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 (project)

// 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 (mobile)

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。enter image description here


答案 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 了解更多详情。


答案 2

以下内容对我有用:

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

推荐