How to add an external library to IntelliJ IDEA?

I am trying to add an external library (puts it in the / libs directory) in my project. When I try to use methods from this library, I see that they are red, which means that the library is not recognized. When I press Ctrl + B, I get the message "I can not find the ad to go to."

I use these steps to add a library (JAR file): 1. Copy the library file to the / libs directory 2. Open the project structure β†’ Global libraries β†’ Attach treasures 3. Find the library and click ok

Is this the right way to do this?

PS. I am trying to add an admob.jar file this way.

+77
intellij-idea
Aug 15 '11 at 13:20
source share
5 answers

Simple procedure in recent versions:

  • Copy the jar to the libs directory in the application (you can create a directory if not there)
  • Refresh the project so that the libraries appear in the structure (right-click on the top level of the project, update / synchronize)
  • Expand libs and right click on the jar
  • Select Add As Library

Done

+139
Apr 12 '13 at 0:00
source share

I used this process to attach a third-party Jar to an Android project in IDEA.

  • Copy the Jar to the libs / directory
  • Open project settings (Ctrl Alt Shift S)
  • In the Project Settings panel on the left, select Modules.
  • In the larger panel, select the Dependencies tab
  • Click the "Add" button in the far right corner of the screen (if you have a smaller screen such as me, you may need to move the size to the right to see it)
  • From the Add Options drop-down list, select Library. A "Select Libraries".
  • Click "New Library ..."
  • Choose a suitable title for the library
  • Click "Attach classes ..."
  • Select Jar from your libs / directory and click OK to reject

The library should now be recognized.

+63
Aug 15 2018-11-11T00:
source share

Intellij IDEA 15: File-> Project Structure ...-> Project Settings-> Libraries

+6
Jan 15 '16 at 21:29
source share

The best way in the long run is to integrate Gradle into the project environment. Its a build tool for Java, and now it is used a lot in the Android development space.

You will need to create a .gradle file and list the dependencies of your library. Then all you have to do is import the project into IntelliJ using Gradle.

Greetings

+1
Oct 31 '14 at 0:08
source share

This question can also be expanded, if necessary, the jar file can be found in the global library, as you can configure it in your current project.

Processes like these: "project structure" β†’ "modules" β†’ "click on your current project panel on the right" β†’ "dependencies" β†’ "click" add "(+)" β†’ "library" β†’ "select the desired library".

if you use maven, and you can also configure the dependency in your pom.xml, but your version of your choice is not like a global library, you will waste memory saving another version of the same jar file. therefore, I suggest using the first step.

0
Oct. 16 '16 at 14:21
source share



All Articles