Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add commons-io dependency to gradle project in Android Studio

Very simple question - how to add commons-io dependency to gradle Android project?

I tried the following

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}

apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
    compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}

but it does not work The error is

Gradle: A problem occurred configuring project ':LearnIt'.

Failed to notify project evaluation listener. Could not resolve all dependencies for configuration ':LearnIt:_DebugCompile'. > Could not find commons-io:commons-io:2.0.1. Required by: learnit:LearnIt:unspecified

like image 505
Georgy Buranov Avatar asked Jul 27 '13 07:07

Georgy Buranov


3 Answers

As of now (May 2014) if you use the default generated project it is actually amazingly simple (though difficult to find instructions!

Open the second level build.gradle, and add the following line to the dependencies {:

compile "commons-io:commons-io:+"

That will get the latest version of commons-io. My complete file looks like this:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile "commons-io:commons-io:+"
}
like image 155
Timmmm Avatar answered Oct 31 '22 18:10

Timmmm


you need to declare a repository where you want to resolve the commons-io library from (e.g. MavenCentral):

buildscript {
    repositories {
        mavenCentral()
    }

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

apply plugin: 'android'

repositories{
    mavenCentral()
}

dependencies {
    compile files('libs/android-support-v4.jar')

    compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}    
like image 44
Rene Groeschke Avatar answered Oct 31 '22 17:10

Rene Groeschke


Use gradlePlease to get the dependency.

Add the following to your app/build.gradle file:

dependencies {
    compile 'org.apache.commons:commons-io:1.3.2'
}

//UPDATED

implementation group: 'commons-io', name: 'commons-io', version: '2.6'
like image 47
Sam Avatar answered Oct 31 '22 18:10

Sam