Android Studio: Add jar as library?

后端 未结 30 2435
天命终不由人
天命终不由人 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:57

    I have read all the answers here and they all seem to cover old versions of Android Studio!

    With a project created with Android Studio 2.2.3 I just needed to create a libs directory under app and place my jar there. I did that with my file manager, no need to click or edit anything in Android Studio.

    Why it works? Open Build / Edit Libraries and Dependencies and you will see:

    {include=[*.jar], dir=libs}
    
    0 讨论(0)
  • 2020-11-21 06:57
    1. Added the libs folder at the level of app.
    2. Added all the jars in this project.
    3. Next, selected all the jars, in the libs folder,
    4. right click on the selected items, and say add library
    5. then you will find the jars expansion option, within the project explorer itself.

    I observed CTRL + ALT + SHIFT + S --> project structure --> app-module -->Dependencies" already had an entry as (dir: 'libs', include: '*.jar') under compile-option, initially. And after adding the jar's as per the steps stated above, the build.gradle got the entries for the new added jar's, itself.

    0 讨论(0)
  • 2020-11-21 06:58

    In the project right click

    -> new -> module
    -> import jar/AAR package
    -> import select the jar file to import
    -> click ok -> done
    

    Follow the screenshots below:

    1:

    2:

    3:

    You will see this:

    0 讨论(0)
  • 2020-11-21 06:58

    Step 1 : Now under your app folder you should see libs, if you don't see it, then create it .

    Step 2 : Drag & Drop the .jar file here, you may be get a prompt "This file does not belong to the project", just click OK Button .

    Step 3 : Now you should see the jar file under libs folder, right click on the jar file and select "Add as library", Click OK for prompt "Create Library"

    Step 4 : Now this jar has been added.

    0 讨论(0)
  • 2020-11-21 06:59
    1. Download Library file from website
    2. Copy from windows explore
    3. Paste to lib folder from Project Explorer
    4. Ctrl+Alt+Shift+S open Project Structure
    5. Select Dependencies Tab, add the file by using +
    6. Tool bar Sync project with gradle file by using button

    That solved my problem. Try, if anyone want more details let me know.

    0 讨论(0)
  • 2020-11-21 06:59

    Create a folder libs. Add your .jar file. Right click on it and you will find add jar as dependency. Click on it. Its all you need to do. You can find the dependencies added to your build.gradle file.

    0 讨论(0)
提交回复
热议问题