javaandroidandroid-studio-import

How to use the gson library from google


I am trying to use the google gson library in android studio, but I can't import it. I've added the .jar file to the libs folder, and I added

compile fileTree(dir: 'libs', include: ['*.jar'])

to my app build.gradle dependencies. There's no option to add library when I right click the .jar file.

Then, is there a package statement I need to write? Or an import?

I'm very new to java, and help is very much appreciated. Thanks in advance!


Solution

  • You should add in your build.gradle, inside the dependencies the following:

      compile 'com.google.code.gson:gson:2.8.5'
    

    Then sync project and you will have gson included!

    Here is the repo of gson: https://mvnrepository.com/artifact/com.google.code.gson/gson/2.8.5