Android Studio: Add jar as library?

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

    You can do this with two options.

    first simple way.

    Copy the .jar file to clipboard then add it to libs folder. To see libs folder in the project, choose the project from combobox above the folders.

    then right click on the .jar file and click add as a library then choose a module then ok. You can see the .jar file in build.gradle file within dependencies block.

     dependencies {
            implementation fileTree(dir: 'libs', include: ['*.jar'])
            implementation 'com.android.support:appcompat-v7:21.0.3'
            implementation project(':okhttp-2.0.0')
            implementation 'com.google.code.gson:gson:2.3.1'
        }
    

    Second way is that: We can add a .jar file to a module by importing this .jar file as a .jar module then add this module to any module we want.

    import module ---> choose your .jar file --> than import as a .jar -- enter image description here

    Then CTRL+ALT+SHIFT+S --> project sturure -->choose the module you want ato add a jar -->Dependencendies --> Module Dependency. build.gradle of the module will updated automatically. enter image description here

提交回复
热议问题