We can find some very good open source libraries for android. I want to know what is the best way to integrate them to our own projects in Android studio. Here are some basic methods:
- Copy the source code and resource files into our own project. We need to change a lot of codes (the package name, and the name in xml,etc)
- If jar files is provided, I just create libs folder for my project and copy the jar files inside. And add the jar file in Module setting's dependencies. But unfortunately I got a lot of error messages like "Gradle: Package com.google.gson doesn't exist".
Is there a general rule to add third party source or jar files into an existing android studio project? Thanks
Download and copy your jar to libs folder then add the following to your app.gradle file and SYNC.
I prefer to use central repository for dependencies management. So for
gson 2.3
dependency you should add tobuild.gradle
file:Specify that you want to use maven central repository for your dependency
repositories {jcenter()}
Add
compile
dependency togson 2.6.2
dependencies {compile 'com.google.code.gson:gson:2.6.2'}
Android Studio as well as your CI server should easily build your project now. And you can continue app development.
I prefer to use central repository for dependencies management because:
Examples:
I should notice:
gson-2.2.4.jar
) into the libs foldercompile files('libs/gson-2.2.4.jar')
is in yourbuild.gradle
filegradlew clean
. I'm on Mac OS X, the command might be different on your systemThis series of steps was taken from Android Studio: Add jar as library? and is not my original answer. I am posting them here, again, because your question was the third in search results on Google when looking up this same topic. Hence, copying.
All credits to the one who wrote the steps.
Download & Copy Your
.jar
file inlibs
folder then adding one line to build.gradle:Do not forget to click "Sync now"
I´m using Android Studio 1.1.0