Java “无法解决:com.android.support:support-v4:26.0.0”和 Gradle 同步上的其他类似错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45385199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Failed to resolve: com.android.support:support-v4:26.0.0" and other similar errors on Gradle sync
提问by George B
I have just created a new Android Studio project for both Android Mobile andwear. The initial gradle build failed because I am getting several errors-
我刚刚为 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:support-v4:26.0.0
Error: Failed to resolve: com.android.support:percent: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:recyclerview-v7:26.0.0
Error: Failed to resolve: com.android.support:support-annotations: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!
对于每个错误,我都可以选择Install repository and sync project
,但是当我单击它时没有任何反应。我花了几个小时试图找出我收到这些错误的原因,但我找不到任何解决方案。有人知道如何解决这些非常令人沮丧的错误吗?谢谢!
build.gradle (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 (mobile)
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 (wear)
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+"
}
I am sure that my version of Android Studio is updated, and all support repositories and APIs are installed.
采纳答案by George B
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 Platform 26创建了项目。但是,Wear目前不支持26,并且必须在build的wear模块中将target
和compile
SDK版本更改为25。毕业。
Link to Android Developers documentation - https://developer.android.com/training/wearables/apps/creating.html#setting-up-a-phone
链接到 Android 开发人员文档 - https://developer.android.com/training/wearables/apps/creating.html#setting-up-a-phone
build.gradle (wear)
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'
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.
我只需要在磨损模块中将编译和目标 SDK 版本更改为 25。对于移动模块,我将它们保留为 26。
回答by Anil
Add following dependency in your gradle
在您的 gradle 中添加以下依赖项
Replace
代替
compile 'com.android.support:support-v4:26.0.0'
with
和
compile 'com.android.support:support-v4:25.0.0'
and Replace
并替换
compile 'com.android.support:appcompat-v7:26+'
with
和
compile 'com.android.support:appcompat-v7:25.0.0'
回答by Arjun Thakuri
Either change your build tool version from 26.0.1
to 26.0.0
or you can replace 26.0.0
by 26.+
like below.
将您的构建工具版本从 更改为26.0.1
,26.0.0
或者您可以替换26.0.0
为26.+
如下所示。
compile 'com.android.support:support-v4:26.0.0'
to
到
compile 'com.android.support:support-v4:26.+"
Do same with all... Hope it helps. Happy Coding! ^_^
对所有人做同样的事情......希望它有帮助。快乐编码!^_^
回答by Hamid Reza
Replace this:
替换这个:
compile 'com.android.support:recyclerview-v7:26.0.0'
With this
有了这个
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
Do same with all
对所有人做同样的事情
Update - new version released
更新 - 新版本发布
compile 'com.android.support:recyclerview-v7:26.1.0'
回答by John Smith
For now, I fixed this with changing in the wear build.gradle:
现在,我通过改变wear build.gradle 来解决这个问题:
compile 'com.google.android.support:wearable:2.0.3'
provided 'com.google.android.wearable:wearable:2.0.3'
It seems like the problem is com.google.android.support:wearable:2.0.4. With that, Using 26.0.1 build tools compiles fine. I haven't gone any further with this but it looks like a dependency problem related to a repository although that is really just a guess from the error messages.
问题似乎是 com.google.android.support:wearable:2.0.4。有了这个,使用 26.0.1 构建工具编译得很好。我没有更进一步,但它看起来像是与存储库相关的依赖问题,尽管这实际上只是错误消息的猜测。
回答by Parkbrakereminder
The following worked for me:
以下对我有用:
In the Application build.gradle considered to add following:
在 Application build.gradle 中考虑添加以下内容:
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
in the Module build.gradle:
在模块 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'
}
回答by FL.S
I meet this problem, changing the build tool/ sdk version didn't work, clearly write compile version didn't work, off line build didn't work.
我遇到了这个问题,更改构建工具/ sdk版本不起作用,显然写编译版本不起作用,离线构建不起作用。
Finally I just change wearable version, and this problem gone.
最后我只是更换了可穿戴版本,这个问题就消失了。
provided 'com.google.android.wearable:wearable:2.0.4'
compile 'com.google.android.support:wearable:2.0.4'
to
到
provided 'com.google.android.wearable:wearable:2.0.2'
compile 'com.google.android.support:wearable:2.0.2'
By the way, I used offline building now because it is really fast when I check this issue.
顺便说一句,我现在使用离线构建,因为当我检查这个问题时它真的很快。
回答by Kevin
I don't have an Android wear project, but I had the same problem when I wanted to upgrade the Support Library version for an existing project to 26.0.0. Since 26.0.0 the support libraries are available through Google's Maven repository. So I had to add the repository to my build. gradle file.
我没有 Android Wear 项目,但是当我想将现有项目的支持库版本升级到 26.0.0 时遇到了同样的问题。从 26.0.0 开始,支持库可通过 Google 的 Maven 存储库获得。所以我不得不将存储库添加到我的构建中。gradle 文件。
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Check out https://developer.android.com/topic/libraries/support-library/setup.htmlfor more details.
查看https://developer.android.com/topic/libraries/support-library/setup.html了解更多详情。
回答by Thunderstick
Add the following dependencies in your app/build.gradle
.
在您的app/build.gradle
.
repositories {
maven { url 'https://maven.fabric.io/public' }
maven{url 'https://maven.google.com'}
}
回答by HSpector
This one worked for me
这个对我有用
allprojects {
repositories {
jcenter()
google()
}
}
google()does the magic with the following configuration
google()使用以下配置实现了魔法
Studio version : 3.0 beta 2
工作室版本: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