Adding Joda Time to Android Studio
Asked Answered
H

4

48

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?

Hardtack answered 24/3, 2015 at 16:8 Comment(1)
Please show us your gradle build configuration file.Pivoting
H
130

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.

Holeandcorner answered 24/3, 2015 at 16:20 Comment(14)
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 2Ancel
using compile 'joda-time:joda-time:+' new versions will be downloaded automaticallyEnvelopment
@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.Amongst
Just a friendly reminder that 2.9.2 is out now: github.com/JodaOrg/joda-time/releasesKipkipling
@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.Holeandcorner
@AmitK.Saha: True. I'll keep in mind from next time!Maffick
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...Musselman
you should ask a new question regarding this.Holeandcorner
I get Failed to resolve: 'joda-time:joda-time:2.9.3' when I try sync my project?Ferdie
compile 'joda-time:joda-time:2.9.3', are you sure there is no typo in your gradle dependencies?Holeandcorner
@Ferdie uncheck offline mode in File->Settings->Gradle and it might workDuthie
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?Angie
I think a better place to look for updates is mavenRodas
@Kenneth Worden, Yes, you are right. - https://dl.bintray.com/jodastephen/maven - https://mvnrepository.com/artifact/joda-time/joda-time/2.9.9Inness
K
15

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.

Kudu answered 25/6, 2016 at 17:5 Comment(0)
T
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...

Twospot answered 5/10, 2016 at 15:55 Comment(0)
I
0

Android Studio Iguana | 2023.2.1 I was added dependency in build.gradle.kts file as follows.

dependencies {
    implementation ("joda-time","joda-time","2.9.1")
}

It is work!!!

If answered 21/5 at 17:37 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Nide

© 2022 - 2024 — McMap. All rights reserved.