Thursday, January 19, 2017

Adding a JAR to an Android Studio Project

I recently needed to add some TFTP functionality to an Android app I've been working on. I opted to leverage the Apache Software Foundation's Commons-Net libraries. If you download the binaries, there is a .jar file you can use in your Android project.

To import the library into your Android Studio project, it's pretty simple.

  1. Create a new directory (if it isn't there) in your project called "libs."
  2. Copy the .jar file to your clipboard.
  3. In Android Studio's "Project" view, expand your project's app/libs branches.
  4. Paste the .jar file to the libs directory.
  5. Right click the .jar file, and then choose "Add As Library."
At this point, Gradle will rebuild, incorporating the new library into your project's builds; so at this point, you should be good to go. Import your library as needed and use it.