Qing
Qing

Reputation: 1411

Could not find junit:junit:4.12 in Android Studio

Im new to testing in android studio, im was trying to setup the gradle for adding dependencies for Junit4.

However, the gradle console informs me "Could not find junit:junit:4.12."

It seems like gradle search the dependency in local folder instead of via internet, please inform how I should setup the gradle file for adding the dependecy for Junit.

enter image description here

enter image description here

Upvotes: 1

Views: 9375

Answers (3)

Austine
Austine

Reputation: 11

Try commenting out //testCompile 'junit:junit:4.12'.

This will solve the problem if you don't have internet access as you run app after installing Android Studio. As soon as you have internet access, uncomment and run your app, there after everything remains fixed won't be needing internet access again.

I'm sure it works. Not sure why, anyway.

Upvotes: 1

Henry
Henry

Reputation: 17841

You have in your build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
}

The above will fetch the plugin com.android.application. That's all it will do.

You should have the below to fetch all your dependencies:

repositories {
    mavenCentral()
}

Upvotes: 0

KhogaEslam
KhogaEslam

Reputation: 3046

You need internet connection -at least first time- to build project first time correctly (i really don't know why) !!!

so, to avoid that you may try download JUnit (required library) from here and add it manually to your application into ~[YourAppFolder]\app\libs

then rebuild your app.

Upvotes: 2

Related Questions