“无法解析: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

查看:40
本文介绍了“无法解析:com.android.support:support-v4:26.0.0"和 Gradle 同步上的其他类似错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚为 Android Mobile Wear 创建了一个新的 Android Studio 项目.最初的 gradle 构建失败,因为我收到了几个错误-

I have just created a new Android Studio project for both Android Mobile and wear. The initial gradle build failed because I am getting several errors-

错误:无法解析:com.android.support:support-v4:26.0.0

错误:无法解析:com.android.support:percent:26.0.0

错误:无法解析:com.android.support:recyclerview-v7:26.0.0

错误:无法解析:com.android.support:support-annotations:26.0.0

对于每个错误,我都可以选择安装存储库和同步项目,但是当我点击它时没有任何反应.我花了几个小时试图找出我收到这些错误的原因,但我找不到任何解决方案.有人知道如何解决这些令人沮丧的错误吗?谢谢!

With each error, I am given the option to Install repository and sync project, but nothing happens when I click on it. I have spent several hours trying to find why I am getting these errors, but I can't find any solutions. Does anybody know how to fix these very frustrating errors? Thank you!

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 均已安装.

I am sure that my version of Android Studio is updated, and all support repositories and APIs are installed.

推荐答案

我的项目给我这些错误的原因是因为我为 Android Platform 26 创建了项目.但是,Wear 目前不支持 26,它在 build.gradle 的wear 模块中将targetcompile SDK 版本更改为25 是必不可少的.

The reason that my project was giving me these errors was because I created the project for Android Platform 26. However, Wear currently doesn't support 26, and it is essential to change the target and compile SDK versions to 25 in the wear module of build.gradle.

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

Link to Android Developers documentation - 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.

I only needed to change the compile and target SDK versions to 25 in the wear module. I left them as 26 for the mobile module.

这篇关于“无法解析:com.android.support:support-v4:26.0.0"和 Gradle 同步上的其他类似错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆