Android Studio: Add jar as library?-open source projects forkhubs/android
Andromeda
You can do this with two options.
first simple way.
Copy the .jar file to clipboard then add it to libs folder. To see libs folder in the project, choose the project from combobox above the folders.
then right click on the .jar file and click add as a library then choose a module then ok. You can see the .jar file in build.gradle file within dependencies block.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':okhttp-2.0.0')
compile 'com.google.code.gson:gson:2.3.1'
}
Second way is that: We can add a .jar file to a module by importing this .jar file as a .jar module then add this module to any module we want.
import module —> choose your .jar file –> than import as a .jar —
Then CTRL+ALT+SHIFT+S –> project sturure –>choose the module you want ato add a jar –>Dependencendies –> Module Dependency. build.gradle of the module will updated automatically.