Android Studio 无法解析 Espresso 3.0.0
Android Studio can't resolve Espresso 3.0.0
根据 Android Espresso documentation 至今:
Add Espresso dependencies
To add Espresso dependencies to your project, complete the following steps:
- Open your app’s build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle.
- Add the following lines inside dependencies:
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
androidTestCompile 'com.android.support.test:runner:1.0.0'
我新建了一个项目,生成的app/gradle文件是这样的:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
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'
})
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
}
当我将其更改为以下内容时:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
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'])
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
// App's dependencies, including test
compile 'com.android.support:support-annotations:22.2.0'
// Testing-only dependencies
androidTestCompile 'com.android.support.test:runner:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
}
我收到以下错误:
Error:(29, 24) Failed to resolve: com.android.support.test:runner:1.0.0
Install Repository and sync project
Error:(30, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.0
Install Repository and sync project
我尝试点击“安装存储库和同步项目”link,但没有任何反应。我也试过查看 SDK 管理器,但我真的看不到任何东西。
由于评论中的解决方案正在解决问题,我将其添加为其他人的答案:
务必将 Google's maven link 添加到主 build.gradle
文件中:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
使用这些版本
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
简单地说,
将 google()
添加到 allprojects > repositories
中即可解决问题...
allprojects {
repositories {
google()
jcenter()
}
}
您可以降级版本,但有时目标版本无法从存储库中获得。
使用IDE-UI到select最新版本:
- 右键单击您的项目文件夹,select
Open Module Settings
- 在依赖中搜索你想要的包,例如
这样,您将永远不会获得不可用的版本
(当然记得也要在 build.gradle
中设置适当的 repo)
根据 Android Espresso documentation 至今:
Add Espresso dependencies
To add Espresso dependencies to your project, complete the following steps:
- Open your app’s build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle.
- Add the following lines inside dependencies:
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
androidTestCompile 'com.android.support.test:runner:1.0.0'
我新建了一个项目,生成的app/gradle文件是这样的:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
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'
})
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
}
当我将其更改为以下内容时:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 24
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'])
compile 'com.android.support:appcompat-v7:26.+'
testCompile 'junit:junit:4.12'
// App's dependencies, including test
compile 'com.android.support:support-annotations:22.2.0'
// Testing-only dependencies
androidTestCompile 'com.android.support.test:runner:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
}
我收到以下错误:
Error:(29, 24) Failed to resolve: com.android.support.test:runner:1.0.0
Install Repository and sync project
Error:(30, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:3.0.0
Install Repository and sync project
我尝试点击“安装存储库和同步项目”link,但没有任何反应。我也试过查看 SDK 管理器,但我真的看不到任何东西。
由于评论中的解决方案正在解决问题,我将其添加为其他人的答案:
务必将 Google's maven link 添加到主 build.gradle
文件中:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
使用这些版本
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
简单地说,
将 google()
添加到 allprojects > repositories
中即可解决问题...
allprojects {
repositories {
google()
jcenter()
}
}
您可以降级版本,但有时目标版本无法从存储库中获得。 使用IDE-UI到select最新版本:
- 右键单击您的项目文件夹,select
Open Module Settings
- 在依赖中搜索你想要的包,例如
这样,您将永远不会获得不可用的版本
(当然记得也要在 build.gradle
中设置适当的 repo)