Android Studio: Add jar as library?

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

    With Android Studio 3+:

    You should just be able to simply copy the jar file to the libs folder right under the app folder.

    ... myproject\app\libs\myfile.jar

    Then select Project Files from the drop-down on the Projects window, right click on the project, select Synchronize to see the file in Project Files. It will automatically add the dependencies in the gradle file (Module:app).

    dependencies {
    ...
        implementation files('libs/myfile.jar')
    

    Here is another solution:

    Go to the Project Files view (select Project Files from the dropdown).

    Select New... Directory, create a folder named libs right under app.

    Open up File Explorer, copy and paste your jar file into the libs folder.

    In Android Studio, right click on the jar file, and select Add as a Library... from the popup menu.

    You should see the file listed in the dependencies list in the gradle file:

    dependencies {
    ...
        implementation files('libs/myfile.jar')
    }
    

    Open up your java file, and add the import statement there:

    import com.xxx.xxx;
    

提交回复
热议问题