【问题标题】:Failed to resolve: junit:junit:4.12无法解决:junit:junit:4.12
【发布时间】:2016-10-13 19:45:52
【问题描述】:

我刚刚在我的工作计算机上安装了 Android Studios,并创建了一个新的空白项目。但是,我收到以下错误。

无法解决:junit:junit:4.12

从上一次被问到这个问题时,我尝试了许多解决方案,但似乎没有一个有效。我尝试注释掉整行 compile files('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
}

【问题讨论】:

  • 请添加全局 build.gradle 文件(这是特定于应用程序的)
  • 对不起@MatiasElorriaga,我不太明白。你能告诉我更详细的吗?
  • 你的项目中应该有两个 build.gradle 文件。请添加另一个(一个已经发布:P)
  • 完成!检查编辑。很抱歉@MatiasElorriaga

标签: android android-gradle-plugin junit4


【解决方案1】:

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
}

复制

首先从build.gradle (模块级别)部分中删除compile files('libs/junit-4.12.jar')

然后清理-重建-Gradle-运行

【讨论】:

【解决方案2】:

尝试将mavenCentral() 添加为存储库,同时删除compile files('libs/junit-4.12.jar')

buildscript {
    ...
    repositories {
        mavenCentral()
    }
    ...
}

【讨论】:

  • 我现在必须下班,但明天我会再次尝试您的解决方案并通知您!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-03
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-07
  • 1970-01-01
相关资源
最近更新 更多