无法在 Android Studio 新项目中解析 com.android.support:appcompat-v7:26.1.0 [英] Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project
问题描述
我知道这个问题:
无法解决:com.android.support:cardview-v7:26.0.0 android
无法解析 com.android.support:appcompat-v7:26.1.0 [重复]
我已经阅读了这些文档:
迁移到适用于 Gradle 3.0 的 Android 插件.0
所以我发布这个问题是相信它不是重复的.
我已经安装了 Android Studio 3.0.1.我之前没有任何以前的版本,我开始了一个新项目.
Gradle 文件中的每个设置都是由 Android Studio 自己设置的,我已经全部检查过了.
这些是文件内容:
build.gradle(模块:app)
应用插件:'com.android.application'安卓 {compileSdkVersion 26默认配置{applicationId "com.example.administrator.as301test"minSdk 版本 16目标SDK版本26版本代码 1版本名称1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}依赖{实现文件树(目录:'libs',包括:['*.jar'])实现 'com.android.support:appcompat-v7:26.1.0'实现 'com.android.support.constraint:constraint-layout:1.0.2'实现 '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 {存储库{谷歌()jcenter()}依赖{类路径 'com.android.tools.build:gradle:3.0.1'//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}所有项目{存储库{谷歌()jcenter()}}任务清理(类型:删除){删除 rootProject.buildDir}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME分布路径=包装器/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
我在存储库中使用 google()
作为 此处 明确表示:
//如果您使用的是低于 4.1 的 Gradle 版本,则必须改为使用://行家{//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
最后我通过像这样修改 build.gradle
解决了这个问题:
android {compileSdkVersion 26构建工具版本26.0.2"默认配置{minSdk 版本 16目标SDK版本26}}依赖{实现文件树(目录:'libs',包括:['*.jar'])实现 'com.android.support:appcompat-v7:26.1.0'实现 'com.android.support.constraint:constraint-layout:1.0.2'实现 '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'
在将现有项目从 2.3 迁移到 3.0.1 以及像这样修改项目 gradle 文件时,我也遇到了同样的问题,我想出了一个可行的解决方案:
build.gradle(模块应用)
android {compileSdkVersion 27构建工具版本27.0.1"默认配置{applicationId "com.mobaleghan.tablighcalendar"minSdk 版本 16目标SDK版本27}依赖{实现 'com.android.support:appcompat-v7:25.1.0'实现 'com.android.support:design:25.1.0'实现 'com.android.support:preference-v7:25.1.0'实现 'com.android.support:recyclerview-v7:25.1.0'实现 'com.android.support:support-annotations:25.1.0'实现 'com.android.support:support-v4:25.1.0'实现 'com.android.support:cardview-v7:25.1.0'实现 'com.google.android.apps.dashclock:dashclock-api:2.0.0'}
顶级 build.gradle
buildscript {存储库{谷歌()jcenter()}依赖{类路径 'com.android.tools.build:gradle:3.0.1'}}所有项目{存储库{谷歌()jcenter()}}
I know about this questions:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]
And I've read this documentations:
Migrate to Android Plugin for Gradle 3.0.0
So I'm posting this question believing its not a duplicate.
I've installed Android Studio 3.0.1. I didn't have any previous version before and I started a new project.
Every setting in Gradle file have been set by Android Studio itself and I've checked them all.
These are the file contents:
build.gradle (Module: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'
}
Top level 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
I use google()
in repositories as here clearly says:
// If you're using a version of Gradle lower than 4.1, you must instead use: // maven { // url 'https://maven.google.com' // }
My gradle version is 4.1 so I don't need above code.
But I still get this error as the others have been asking about:
Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.
Why should I get this error when I'm creating a new project in AS 3.0.1
and it has been set all the necessary settings?
Update
@Rohit's answer somehow solved the issue but I still get same error for some other dependencies.
Could not resolve com.android.support.test:runner:1.0.1
Could not resolve com.android.support.test.espresso:espresso-core:3.0.1
Could not resolve junit:junit:4.12
Finally I fixed the problem by modifying build.gradle
like this:
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
}
}
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'
}
I've removed these lines as these will produce more errors:
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'
Also I had same problem with migrating an existing project from 2.3 to 3.0.1 and with modifying the project gradle files like this, I came up with a working solution:
build.gradle (module app)
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.mobaleghan.tablighcalendar"
minSdkVersion 16
targetSdkVersion 27
}
dependencies {
implementation 'com.android.support:appcompat-v7:25.1.0'
implementation 'com.android.support:design:25.1.0'
implementation 'com.android.support:preference-v7:25.1.0'
implementation 'com.android.support:recyclerview-v7:25.1.0'
implementation 'com.android.support:support-annotations:25.1.0'
implementation 'com.android.support:support-v4:25.1.0'
implementation 'com.android.support:cardview-v7:25.1.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
}
Top level build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
这篇关于无法在 Android Studio 新项目中解析 com.android.support:appcompat-v7:26.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!