androidandroid-studiotime4j

How do you import a library in the most recent and up-to-date versions of Android Studio (2017, 2.3.1+)?


I'm wondering about this. I've been trying to import a library ("Time4J" Android version "Time4A") to a project in the Android Studio, and had to try a number of different things before getting it to "work". I finally managed to get it to import without errors, but now it crashes and doesn't want to work. Somehow I had managed to import it before and it worked without crashing, now I can't replicate that.

The problem seems to me that there's a lot of out-of-date information here about how to import libraries, and nothing for the most recent and up-to-date versions of the Android Studio system (so I was using like 2, 3, 4-year old stuff to try and make this work and this changes fast because there doesn't seem to be anything available from 2017.) and I suspect this is why it's not working. How do you correctly import a library in the newest 2017 versions (2.3.1 and up)?


Solution

  • The recommended way is to import libraries as Gradle dependencies. As described on the Time4A GitHub page:

    dependencies {
        compile group: 'net.time4j', name: 'time4j-android', version: '3.33-2017b'
    }
    

    Add this to your build.gradle and it will download and import the library.