我刚刚第一次下载了android studio,而且我得到了gradle错误。我已经下载了SDK提供的所有内容,但仍然存在相同的错误。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.noelly.myapplication"
minSdkVersion 19
targetSdkVersion 25
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'
})
compile 'com.android.support:appcompat-v7:25.+'
testCompile 'junit:junit:4.12'
}
我得到的错误是
(Failed to resolve: com.android.support.appcompat-v7:25.+)
和
(Failed to resolve: com.android.support.espresso:espresso-core:2.2.2)
顺便说一下,所有事情都是最新的,请帮助这真是令人沮丧的开始。
**编辑答案 - 安装工具图片--- sdktoolsscreenshot
代码表单项目build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.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
}
新错误讯息_____ newerrorscreenshot
答案 0 :(得分:4)
failed to resolve com.android.support.espresso:espresso-core:2.2.2
This error can occur when we refactor layout name.
I had the same problem and my mistake was that I had created the layout naming test.xml and then when I refactored that name with like layout_offers.xml, my gradle was changed something like
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.detail_layout.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
})
Whereas It should be like follow
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'
})
So, one solution is that we should avoid using test.xml as a layout name.
答案 1 :(得分:0)
以下是您的gradle文件的外观:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.noelly.myapplication"
minSdkVersion 19
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.android.support:appcompat-v7:25.1.0'
}
<强>更新强>
您下载的SDK一定有问题。导航到C:/ Users / Noelly / AppData / Local / Android / Sdk / extras / android / m2repository / com / android并删除support
文件夹。
现在打开SDK Manager并重新安装Android Support Repository。
答案 2 :(得分:0)
重命名布局文件后,我收到了同样的错误消息,尽管之前所有内容都已完成。我通过从gradle注释掉这些行来解决这个问题:
androidTestCompile('com.android.support.detail_layout.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
我不知道为什么会这样,或者这是一个很好的修复方法,只是希望这对于像我这样的初学者来说可以快速解决。
答案 3 :(得分:0)
我遇到了同样的麻烦,我找到了解决问题的方法。 这是因为我使用的是x86操作系统,而android studio则是x64。 我去了https://developer.android.com/studio/index.html并按了'下载选项',并安装了x86版本的android studio。 不要卸载以前的x64 android studio。这是因为android sdk所必需的。 在任何地方解压缩你的x86 android studio,找到'bin'文件夹。应该有你的'studio.exe'。