knirirr knirirr - 3 months ago 26
Android Question

org.apache.commons in Android Studio build.gradle file

I've got an old Android project with the following build.gradle file:

apply plugin: 'com.android.application'

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

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 116
}
}

dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}


Syncing the project with gradle files results in:

Failed to resolve org.apache.commons:commons-lang3:3.4


But, I think I've got the syntax correct according to this:

https://search.maven.org/#artifactdetails%7Corg.apache.commons%7Ccommons-lang3%7C3.4%7Cjar

Can anyone tell me what I'm missing here?

N.B. if I download the jar and put it in my project's libs directory then uncomment the fileTree line everything works, though I am told that I am not supposed to be doing this.

Answer

problem is that you are missing this at the top level :You also need repositories and dependencies at the top level for the dependencies for your project itself.For more information you can see these solutions commas error and also here .

apply plugin: 'android'

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 116
    }
}

repositories{
    mavenCentral()
}


dependencies {
    //compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
}

May it helps and solve problem.