Using Jcenter with gradle in Android studio

errolflynn picture errolflynn · Sep 25, 2015 · Viewed 8.4k times · Source

Edit: Figured it out, I implemented JBaruch's suggestion to the allprojects->repositories section of the project-wide build.gradle file.

I am writing a project that depends upon IOIO. Compiling IOIO's libs on my project is giving me trouble. I have tried placing the .aar and .jar files directly in my libs/ directory. However, working with .aar files in gradle is proving to be a trouble-mite. Now, I am attempting to use jcenter to find these libs.

Using jcenter as my repository, gradle originally could not resolve

com.github.ytai.ioio:IOIOLibCore

but specifying version number 5.05 fixed this. However, now gradle is failing to resolve

com.sparetimelabs:purejavacomm:0.0.22

which is not a library that I ask to be compiled with my project.

Below is a copy of my app/build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.agrc.elkausbtransfer"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile 'com.github.ytai.ioio:IOIOLibCore:5.05'
        compile 'com.github.ytai.ioio:IOIOLibPC:5.05'
        compile 'com.github.ytai.ioio:IOIOLibAndroid:5.05'
        compile 'com.github.ytai.ioio:IOIOLibAndroidAccessory:5.05'
        compile 'com.github.ytai.ioio:IOIOLibAndroidDevice:5.05'
        /* To use IOIO from source
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile(name: 'IOIOLibAndroid-release', ebxt: 'aar')
        compile(name: 'IOIOLibAndroidAccessory-release', ext: 'aar')
        compile(name: 'IOIOLibAndroidDevice-release', ext: 'aar')
        */
    }

After trying JBaruch's suggestion and adding the maven url to my Project (root) build.gradle file, I noticed that the Gradle Build file looks as follows:

    Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find com.sparetimelabs:purejavacomm:0.0.22.
     Searched in the following locations:
         https://jcenter.bintray.com/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.pom
         https://jcenter.bintray.com/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.jar
         file:/home/eric/Libs/Android/extras/android/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.pom
         file:/home/eric/Libs/Android/extras/android/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.jar
         file:/home/eric/Libs/Android/extras/google/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.pom
         file:/home/eric/Libs/Android/extras/google/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.jar
     Required by:
         ElkaUsbTransfer:app:unspecified
         ElkaUsbTransfer:app:unspecified > com.github.ytai.ioio:IOIOLibPC:5.05

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

BUILD FAILED

Total time: 2.061 secs

I.e., Gradle did not search at the maven url provided. How do I force Gradle to do this?

Answer

JBaruch picture JBaruch · Sep 25, 2015

com.sparetimelabs:purejavacomm:0.0.22 is a transitive dependency of IOIO project. The problem is that Spare time labs has their own repository and doesn't publish their artifacts to Bintray. What you need to do is to add their repository to the list of your repositories in Gradle:

repositories {
    jcenter()
    maven {
       url 'http://www.sparetimelabs.com/maven2'
    }  
}