Java 无法解决:错误:(23, 17) junit:junit:4.12 in android studio 1.4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33782401/
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 : Error:(23, 17) junit:junit:4.12 in android studio 1.4
提问by maia
I am using Android Studio 1.4 and every time I create a new project same error happen
我使用的是 Android Studio 1.4,每次创建新项目时都会发生同样的错误
Error:(23, 17)"Failed to resolve: junit:junit:4.12".
I read previous post about same problem
Error:(23, 17) Failed to resolve: junit:junit:4.12
我阅读了上一篇关于相同问题的帖子
错误:(23, 17)无法解决:junit:junit:4.12
and done all the the given answer but despite adding URL ('http://repo1.maven.org/maven2' and 'http://jcenter.bintray.com/') for missing repository the error remains
并完成了所有给定的答案,但尽管为缺少存储库添加了 URL(' http://repo1.maven.org/maven2' 和 ' http://jcenter.bintray.com/'),错误仍然存在
here is my latest build.gradle code
这是我最新的 build.gradle 代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 14
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 14
targetSdkVersion 14
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.+'
}
采纳答案by Nitro
If you are adding them to buildscript you will get an error.
如果您将它们添加到 buildscript,您将收到错误消息。
It is a difference between the buildscript repository and the repositories for the dependencies. The buildscript is used for gradle build dependencies.
这是 buildscript 存储库和依赖项存储库之间的区别。buildscript 用于 gradle 构建依赖项。
You will need to add the following to your build.gradle file and it should work fine.
您需要将以下内容添加到 build.gradle 文件中,它应该可以正常工作。
repositories {
maven { url 'http://repo1.maven.org/maven2' }
jcenter { url "http://jcenter.bintray.com/" }
}
Following should work:
以下应该工作:
apply plugin: 'com.android.application'
repositories {
maven { url 'http://repo1.maven.org/maven2' }
jcenter { url "http://jcenter.bintray.com/" }
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.application"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
回答by electronix384128
For me it was that allprojects section was missing in the top level gradle build file:
对我来说,顶级 gradle 构建文件中缺少 allprojects 部分:
buildscript {
[...]
}
allprojects { // <-- required!!!
repositories {
jcenter()
}
}
回答by Omid Rostami
- go to the android studio libs directory
(C:\Program Files\Android\Android Studio\lib)
- find
junit-4.12.jar
file - copy the jar file to your project libs folder
(myproject\app\libs)
- open android studio and delete(comment) this line
(testCompile 'junit:junit:4.12')
inbuild.gradle
file in android studio open (libs) directory and right click the jar file then choose
add as a library
just build your project (for more info see below picture)
- 转到android studio libs目录
(C:\Program Files\Android\Android Studio\lib)
- 查找
junit-4.12.jar
文件 - 将 jar 文件复制到您的项目 libs 文件夹中
(myproject\app\libs)
- 打开Android工作室和删除(注释)这一行
(testCompile 'junit:junit:4.12')
的build.gradle
文件 在android studio中打开(libs)目录并右键单击jar文件然后选择
add as a library
只需构建您的项目(有关更多信息,请参见下图)