dependency_android_studio

How to add dependency (.jar) in Android Studio


In this blog post, we’ll learn how to add dependency in Android Studio. Other than like Eclipse, Android Studio, comes up with little confusing in adding dependency but it lot better than Eclipse, where you can import a local file like in Eclipse or directly from the source.

 

Steps to Import Android Library to your Project:

  • Adding Dependency from Online Source
    1. Open Project Structure on Android Studio, Select File → Project Structure or use Shortcuts (Ctrl + Alt + Shift + S).
    2. Under the Project Structure window, on left side – select on the Module, where you want to import the dependency, on the right side – select the Dependency Tab.
    3. Under the Dependency Tab, on the right side, click on the tiny “+” symbol and select the Library Dependency option.
    4. Finally, you’ll get a window where you can search for the dependency by typing a keyword or enter the fully-qualified coordinates. (for e.g. gson or com.google.code.gson) import-studio
  • Adding Dependency from Local File
    1. Change you Project View to Project or Project Files.
    2. Select on the Module, from the drop-down you’ll find “libs” folder (if you don’t, you can create one under the Module section.). Now Copy paste the required Dependency (.jar) file into it.
    3. Open build.gradle (from Module) and code like this.

      or

      Open Dependency Tab from Project Structure as i explained above. Click on the tiny “+” symbol and select File Module option. From the current window, you can find your dependency under the “libs” folder.

    4. Oh ya, Just Don’t forget to “sync” finally.
      import-studio2

About Durga Chiranjeevi

I’m a normal guy, engineer by education who is passionate about Programming and Internet. An android enthusiast, now moving for cross platforms and game development.