我刚在工作计算机上安装了Android Studios,并创建了一个新的空白项目。但是,我收到以下错误。
无法解决:junit:junit:4.12
我曾尝试过多次提出这个问题的解决方案,但这些问题似乎都没有奏效。我尝试评论整行编译文件(' libs / junit-4.12.jar')。我尝试将jar文件从Android studio lib文件夹粘贴到我的项目lib文件夹并将其添加为库。最重要的是,gradle总是花费超过10分钟来构建。所以我想尝试的任何解决方案都需要我一段时间。请帮忙。
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com.example.mabbasi.myapplication"
minSdkVersion 15
targetSdkVersion 24
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(include: ['*.jar'], dir: 'libs')
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:24.2.1'
testCompile 'junit:junit:4.12'
compile files('libs/junit-4.12.jar')
}
build.bradle(项目)
// 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.1'
// 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
}
答案 0 :(得分:3)
JUnit 是Java编程语言的单元测试框架。
JUnit在测试驱动的开发中一直很重要 发展。
首先从项目级别修改build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
首先从compile files('libs/junit-4.12.jar')
(模块级别)部分删除build.gradle
。
然后 Clean-Rebuild-Gradle-Run 。
答案 1 :(得分:0)
尝试添加mavenCentral()
作为存储库,同时删除compile files('libs/junit-4.12.jar')
buildscript {
...
repositories {
mavenCentral()
}
...
}