Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

java - Android studio v2.2.2 error(27,17) failed to resolve junit:junit4.12

I have searched everywhere for this answer and tried multiple ways to fix this but as I'm new to this IDE I need a little help.

All I have done is created an empty project in android studio and before I make changes to the files I cant build and keep coming up with 7 errors in my message gradle sync.

Errors:

  1. (27,17) Failed to resolve: junit:junit:4.12
  2. Failed to resolve: javax.inject:javax.inject:1
  3. Failed to resolve: javax.annotation:javax.annotation-api:1.2
  4. Failed to resolve: com.google.code.findbugs:jsr305:2.0.1
  5. Failed to resolve: org.hamcrest:hamcrest-library:1.3
  6. Failed to resolve: org.hamcrest:hamcrest-integration:1.3
  7. Failed to resolve: com.squareup:javawriter:2.1.1

This is my project called 'myApplication'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
       classpath 'com.android.tools.build:gradle:2.2.2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And this is my build gradle module:app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "test.app.stannah.com.uk"
        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(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:24.2.1'
    testCompile 'junit:junit:4.12'
}

Can someone please tell me what to do to these errors?

Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Remove the unwanted libraries from the build.gradle,

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'
})
testCompile 'junit:junit:4.12'

and also

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...