Handling build dependencies in Android Studio

This details how to handle build dependencies in Android Studio 1.0.2. I'll use an example to illustrate. We'll add a dependency to Apache's http.entity.mime libraries.

Maven library

  1. Go to File -> Project Structure to open the Project Structure dialog.
  2. Click the Dependencies tab.
  3. Click the add button (the + icon).
  4. Choose Library dependency to open the Choose Library Dependency dialog.
  5. Enter org.apache.httpcomponents:httpmime and click the search icon.
  6. Choose one of the results and click the OK button and OK on the Project Structure dialog as well.

Now open your module's build.gradle file (not the project's gradle file) under the Gradle Scripts and note that compile 'org.apache.httpcomponents:httpmime:4.4-beta1' has been added in the dependencies section. All that the previous procedure did is add some config to your build file. Building your project reads this file and does the necessary compilation based on your config.

To show that this library dependency is encapsulated by the entry in the build.gradle file, reopen the Project Structure -> Dependencies tab and note your library is listed. Close the dialog and delete the above line from your build.gradle file. Now reopen the dialog and note that the library is gone.

File dependency (importing jars)

  1. Download the jar you need.
  2. Add it to your module's libs folder. Directly in the file system go to your project folder, and then your module folder (probably mobile), and then libs.
  3. Build your project.

Note that in your module's build.gradle file, in the dependencies section, this line is including those jars you added to your build:

compile fileTree(dir: 'libs', include: ['*.jar'])