I want to add external library https://github.com/foursquare/foursquare-android-oauth to my Android application (I use Android Studio, the instructions provided by lib autho
flatDir { dirs 'aars' }
compile '[group id]:[artifact id]:[version]@aar'
replacing [group id] etc with the various lib attributes
create a sub directory aars
under your project directory
Copy the [youlibrary].aar
to the subdirectory created in 3. above.
Build & Enjoy!
Android studio doesn't use Maven
, it use Gradle
, you can open your build.gradle
the route should be: /app/build.gradle
and add the Gradle dependency that shows on the repo:
The build.gradle
has a dependencies
section:
dependencies {
//here add your dependency
}
The repo says that you need to add this dependency:
compile 'com.foursquare:foursquare-android-oauth:1.0.3'
only add that line to your dependencies
on buil.gradle
, save the file, and android will rebuild the project, that's all
There are some changes in new gradle 4.1
instead of compile we should use implementation
implementation 'com.android.support:appcompat-v7:26.0.0'
Try one of these approaches:
Approach 1)
1- Choose project view
2- Copy your JAR file in app -> lib folder
3- Right click on your JAR file and choose add as library
4- Check it in build.gradle
Approach 2)
1- File -> New -> New Module
2- Import .JAR/.AAR Package
3- Browse your JAR File
4- Finish
5- File -> Project Structure -> Dependencies
6- You should click on + button and then click on Module Dependency
7- You will see your library here
8- choose your library and click ok
9- Then, you will see that your library is added.
For first two approaches, you need a JAR file. You can search http://search.maven.org/ to find JAR files that are related to Android. For example, this is the search result for jdom in this link
Approach 3) Android is using http://jcenter.bintray.com/ as remote library. For example, this is the search result for jdom in the link.
To add a library in this approach, please follow these steps:
1- File -> Project Structure -> Dependencies
2- Click on + button and choose library dependency
3- find your library and select it, then click OK.
I hope it helps.
For the simplest way just follow these steps
Go to File -> New -> Import Module -> choose library or project folder
Add library to include section in settings.gradle file and sync the project (After that you can see new folder with library name is added in project structure)
include ':mylibraryName'
Go to File -> Project Structure -> app -> dependency tab -> click on plus button
Select module dependency -> select library (your library name should appear there) and put scope (compile or implementation)
Add this line in build.gradle in app level module in dependency section
implementation project(':mylibraryName')
Adding library in Android studio 2.1
Just Go to project -> then it has some android,package ,test ,project view
Just change it to Project View
under the app->lib folder
you can directly copy paste the lib and do android synchronize it.
That's it