Monday, 28 October 2013

How to add JAR library to the Android project in Android Studio?

Some times trivial things like adding a lib references becomes a big pain! Adding jar lib to an Android project in Android Studio on Mac was very problematic for me and of course, many other guys!
After checking different web sites and reading through a bunch of questions in stackoverflow, I managed to get it working.
The steps are:
Create a lib folder in your project folder (the inner one) and copy your jar file there.
Edit the build.gradle file (the inner one) and add: compile files ('lib/ks2.jar')
Close the project and open a terminal and go to the folder of your project. There you'll find a file named gradlew, change that to be executable (chmod +x gradlew), then execute it: ./gradlew clean
It would take a while to finish and you should see a 'BUILD SUCCESSFUL' message upon completion. Once done, open the project, and you're done!