47

I got the file from the Joda site and followed these instructions for adding libraries but when I get to the Gradle sync I end up with the error:

Gradle Sync

Error:Configuration with name 'default' not found.

Gradle Build

Error:A problem occurred configuring project ':app'. 
> Cannot evaluate module joda : Configuration with name 'default' not found.

A bit confused, I looked around and read that the library should have it's own gradle files but the joda package doesn't. When I try to use import org.joda.time; it can't resolve joda. Does anyone have any idea of what I'm doing wrong?

Cai
  • 5,063
  • 3
  • 18
  • 23

3 Answers3

128

in app/build.gradle file, add like this-

dependencies {    
    compile 'joda-time:joda-time:2.9.4'
}

You don't need to do anything else.

You need the latest release, check out the release page https://github.com/JodaOrg/joda-time/releases and change the version accordingly.

spaaarky21
  • 6,524
  • 7
  • 52
  • 65
Amit K. Saha
  • 5,871
  • 2
  • 27
  • 35
  • 7
    I am getting this exception when i run the project: `Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2` – Shajeel Afzal May 28 '15 at 20:40
  • 6
    using `compile 'joda-time:joda-time:+' ` new versions will be downloaded automatically – jack_the_beast Oct 08 '15 at 15:17
  • 11
    @JacopoGrassi: Granting unlimited trust (aka depending on most recent version (`+`) you seem to recommend) is pretty simply very unwise. You should always depend on last version you tested it works for you, not the most recent one unconditionally. – Marcin Orlowski Nov 11 '15 at 21:55
  • Just a friendly reminder that 2.9.2 is out now: https://github.com/JodaOrg/joda-time/releases – AdamMc331 Feb 07 '16 at 05:41
  • 1
    @Saket Jain, your edit does not make sense mate as it is already clearly described how to get the latest release version. We don't need to update the answer with each version release. – Amit K. Saha Feb 23 '16 at 20:05
  • @AmitK.Saha: True. I'll keep in mind from next time! – Saket Jain Feb 24 '16 at 07:07
  • 1
    I am getting exception when i add this library in gradle. Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 2... – kirti Hudda Mar 03 '16 at 17:11
  • you should ask a new question regarding this. – Amit K. Saha Mar 09 '16 at 17:57
  • 1
    I get `Failed to resolve: 'joda-time:joda-time:2.9.3' ` when I try sync my project? – Zapnologica Apr 28 '16 at 07:32
  • compile 'joda-time:joda-time:2.9.3', are you sure there is no typo in your gradle dependencies? – Amit K. Saha Apr 29 '16 at 06:10
  • @Zapnologica uncheck offline mode in File->Settings->Gradle and it might work – Klitos G. Jun 03 '16 at 10:56
  • 3
    Can someone explain to me why this works? It's because `joda-time` is in the Maven central repo, and thus we can include it in our gradle, correct? – Kenny Worden Jul 31 '16 at 01:00
  • So, what's the rule of `jitpack.io` in this game? no need to add `maven {url "https://jitpack.io"}` in the top level `build.gradle`? – Mehdi Khademloo Oct 05 '16 at 15:42
  • I think a better place to look for updates is [maven](https://mvnrepository.com/artifact/joda-time/joda-time) – lockwobr Oct 18 '16 at 19:05
  • 1
    @Kenneth Worden, Yes, you are right. - [https://dl.bintray.com/jodastephen/maven](https://bintray.com/jodastephen/maven/joda-time%3Ajoda-time) - [https://mvnrepository.com/artifact/joda-time/joda-time/2.9.9](https://mvnrepository.com/artifact/joda-time/joda-time/2.9.9) – Jeff T. Dec 24 '17 at 10:00
14

I added joda time via File/Project Structure/Modules-App/Dependencies.

enter image description here

Clicking on + and Library dependency brings you to the dialog:

enter image description here

Here you can search for joda and add the actual version to your project. If you add it this way you don't have to manually download the newest version from github or manually write something into your build.gradle file. Android Studio does it all for you.

Christian
  • 25,249
  • 40
  • 134
  • 225
5

I completely prefer to use jitpack.io repository.

In this case, you should get GitHub links of joda-time (just a simple search) and go to Jitpack.IO then search for the github link.

After all, you should get this page and do the instructions.

https://jitpack.io/#JodaOrg/joda-time/v2.9.4

Just sync your gradle and all done...

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mehdi Khademloo
  • 2,754
  • 2
  • 20
  • 40