Android Studio: Add jar as library?

后端 未结 30 3032
天命终不由人
天命终不由人 2020-11-21 05:54

I\'m trying to use the new Android Studio but I can\'t seem to get it working correctly.

I\'m using the Gson library to serialize/deserialize JSON-o

30条回答
  •  甜味超标
    2020-11-21 06:54

    Here are the instructions for adding a local jar file as a library to a module:

    1. Create a 'libs' folder in the top level of the module directory (the same directory that contains the 'src' directory)

    2. In the build.gradle file add the following so that your dependencies closure has:

      dependencies {
          // ... other dependencies
          compile files('libs/')
      }
      
    3. Android Studio should have already setup a gradlew wrapper. From the command line, navigate to the top level of your project (the directory that has a gradlew file).

      Run ./gradlew assemble. This should compile the project with the library. You may need to fix errors in your build.gradle file as necessary.

    4. In order to have Android Studio recognize the local jar files as libraries for support while coding in the IDE, you need to take a few more steps:

      4.1. Right click on the module in the left hand panel and choose Open Library Settings.

      4.2. On the left panel of the dialog, choose Libraries.

      4.3. Click the + sign above the panel second from the left -> Java

      Menu

      4.4. Select your local jar and add it to the project.

    5. You may need to run the above ./gradlew command one more time

提交回复
热议问题