Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why can't android gradle find junit? why isn't it searching for it in remote repositories?

Tags:

android

gradle

why isn't it searching for it in remote repositories?

after all i have at the top of my gradle script mavenCentral()

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

and:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':lvl-licensing')
    testCompile 'junit:junit:4.12'
}

result is:

$ ./gradlew --info build
.
.
.
Creating configuration testReleaseProvided.
Creating configuration testReleaseWearApp.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':myapp'.
> Could not resolve all dependencies for configuration ':myapp:_debugUnitTestCompile'.
   > Could not find junit:junit:4.12.
     Searched in the following locations:
         file:/home/myuser/Android/Sdk/extras/android/m2repository/junit/junit/4.12/junit-4.12.pom
         file:/home/myuser/Android/Sdk/extras/android/m2repository/junit/junit/4.12/junit-4.12.jar
         file:/home/myuser/Android/Sdk/extras/google/m2repository/junit/junit/4.12/junit-4.12.pom
         file:/home/myuser/Android/Sdk/extras/google/m2repository/junit/junit/4.12/junit-4.12.jar
     Required by:
         myapp-container:myapp:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 7.023 secs
Stopped 0 compiler daemon(s).
like image 404
Jas Avatar asked Mar 19 '15 11:03

Jas


People also ask

How does Gradle download dependencies?

At runtime, Gradle will locate the declared dependencies if needed for operating a specific task. The dependencies might need to be downloaded from a remote repository, retrieved from a local directory or requires another project to be built in a multi-project setting. This process is called dependency resolution.

How do I sync Gradle with Android studio?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.

What is module in Gradle?

A module is an isolated piece of the bigger project. In a multi-module project, these modules have their own jobs but work together to form the whole project. Most Android projects only have one module, the app module. The build. gradle (Module: app) file here is in the app folder.


1 Answers

The solution described by @Jas worked for me. But, since I had trouble adjusting build.gradle, I decided to post an answer with the complete change. This is how my build.gradle looks like ath the end:

buildscript {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'    
    }
}

repositories {
    maven { url 'http://repo1.maven.org/maven2' }
}

allprojects {
    repositories {
        maven { url 'http://repo1.maven.org/maven2' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 80
Bob Rivers Avatar answered Sep 23 '22 21:09

Bob Rivers