【发布时间】:2018-05-07 00:09:28
【问题描述】:
我知道这些问题:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]
我已经阅读了这些文档:
Migrate to Android Plugin for Gradle 3.0.0
所以我发布了这个问题,相信它不是重复的。
我已经安装了 Android Studio 3.0.1。我之前没有任何以前的版本,我开始了一个新项目。
Gradle 文件中的每个设置都是由 Android Studio 自己设置的,我已经全部检查过了。
这些是文件内容:
build.gradle(模块:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.administrator.as301test"
minSdkVersion 16
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 {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
顶级 build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
我在存储库中使用google(),因为here 明确表示:
// If you're using a version of Gradle lower than 4.1, you must instead use: // maven { // url 'https://maven.google.com' // }
我的 gradle 版本是 4.1,所以我不需要上面的代码。
但正如其他人一直在询问的那样,我仍然收到此错误:
错误:无法解析 ':app@debug/compileClasspath' 的依赖关系: 无法解析 com.android.support:appcompat-v7:26.1.0。
当我在AS 3.0.1 中创建一个新项目并且已经设置了所有必要的设置时,为什么会出现此错误?
更新
@Rohit 的回答以某种方式解决了这个问题,但对于其他一些依赖项,我仍然遇到同样的错误。
无法解析 com.android.support.test:runner:1.0.1
无法解决 com.android.support.test.espresso:espresso-core:3.0.1
无法解析 junit:junit:4.12
【问题讨论】:
-
测试用例改变你的
buildToolsVersion "26" -
而不是
implementation关键字也尝试使用compile -
@Prem 与
buildToolsVersion "25"的错误相同 -
@AlexJolig 更改为 26
-
取消选中文件->设置->构建、执行、部署->Gradle中的
Offline work选项
标签: android android-gradle-plugin android-studio-3.0