【问题标题】:I have an error in Android studio "Failed to resolve junit:4.12"我在 Android Studio 中出现错误“无法解析 junit:4.12”
【发布时间】:2017-07-14 04:47:16
【问题描述】:

我在安装 Android Studio 2.3.3 后创建了一个新项目,然后由于以下三个错误,Gradle 构建失败:

错误:无法解决:junit:junit:4.12 打开文件
在项目结构对话框中显示

错误:无法解决:org.hamcrest:hamcrest-library:1.3 打开文件
在项目结构对话框中显示

错误:无法解决:org.hamcrest:hamcrest-integration:1.3 打开文件
在项目结构对话框中显示

我尝试查看类似的问题及其答案,但它们对我不起作用。 我尝试删除 gradle.build 中的 testCompile 行,并尝试在 gradle.build 文件中添加 url maven "{ url 'http://repo1.maven.org/maven2' }",我检查了防火墙并下载了 junit.jar,但没有任何效果.

编辑:

build.gradle(模块)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig {
    applicationId "com.example.tasneem.sunshine"
    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'
    }
}
repositories {
    maven { url 'http://repo1.maven.org/maven2' }


   }
}

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:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

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.3.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
}

【问题讨论】:

标签: java android android-studio


【解决方案1】:

首先,连接您的互联网连接,然后更新您的 junit 库。

【讨论】:

  • 已连接。
【解决方案2】:

我想出了一个办法来解决这个问题。这不是错误的解决方案,但如果您遇到与我相同的错误并且没有其他方法有效,它将帮助您运行项目。我下载了一个新的 gradle 并将其解压缩到 C:/Users/Username/gradle/wrapper/dist 文件夹,然后在 Android Studio 中从 file->settings 更改了 gradle 我还在 gradle(模块)文件中注释了整个 testCompile 块,并从项目的模块设置中删除了 junit4.12。 这似乎解决了问题,我可以在我的 Android 设备上运行该项目。

【讨论】:

    猜你喜欢
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    相关资源
    最近更新 更多