和其他类似的Gradle同步错误

和其他类似的Gradle同步错误

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

问题描述

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

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



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

build.gradle(project)

  //顶级构建文件,您可以在其中添加对所有子项目/模块通用的配置选项。 

buildscript {
repositories {
jcenter()
maven {
urlhttps://maven.google.com
}
}

依赖项{
classpath'com.android.tools.build:gradle:2.3.3'

//注意:不要放置你的应用程序依赖关系它们属于单个模块build.gradle文件中的
//
}
}

allprojects {
存储库{
jcenter()



任务清理(类型:删除){
删除rootProject.buildDir
}

build.gradle(手机)

  apply plugin:'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion26.0.1
defaultConfig {
applicationIdcom.georgeberdovskiy.androidweartest
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName1.0
testInstrumentationRunnerandroid.support.test.runner.AndroidJUnitRunner
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro



$ b依赖关系{
编译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项目(':wear')
编译'com.google.android.gms:play-services-wearable:11.0.4'
compile'c​​om.android.support :appcompat-v7:26+'
compile'c​​om.android.support.constraint:constraint-layout:1.0.2'
compilecom.android.support:support-core-utils:26+
testCompile'junit:junit:4.12'
}

build.gradle(wear)

  apply plugin:'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion26.0.1
defaultConfig {
applicationIdcom.georgeberdovskiy.androidwe artest
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir:'libs',include:['* .jar'])
提供'com.google.android.wearable:wearable:2.0.4'
compile'c​​om。 google.android.support:wearable:2.0.4'
compile'c​​om.google.android.gms:play-services-wearable:11.0.4'
compilecom.android.support:support- core-utils:26+

我相信我的Android Studio版本已更新,并安装了所有支持存储库和API。

解决方案

我的项目给我这些错误的原因是因为我为Android平台26创建了该项目。但是,Wear目前不支持26,并且必须更改目标编译在build.gradle的wear模块中将SDK版本设置为25。



链接到Android Developers文档 -



build.gradle(穿着)

  apply plugin:'com.android.application'


android {
compileSdkVersion 25
buildToolsVersion 26.0.1

def aultConfig {
applicationIdcom.georgeberdovskiy.findmyphone
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}

依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
编译'com.google.android.support:wearable: 2.0.3'
'com.google.android.wearable:wearable:2.0.3'
compile'c​​om.google.android.gms:play-services-maps:11.0.4'
编译'com.google.firebase:firebase-core:11.0.4'
编译'com.google.firebase:firebase-database:11.0.4'
编译'com.google.android。 gms:play-services-wearable:11.0.4'

}

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

我只需要改变e磨损模块中的编译和目标SDK版本为25。我把它们留给26作为移动模块。


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-

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

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 (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+"
}

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

解决方案

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.

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

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同步错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 00:19