Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing GSON using gradle

I am trying to import GSON into my project using gradle in android studio. I have used instructions found on google'sGitHub and several stack overflow pages, such as here. However when I go to import into my file using the line

import com.google.gson.Gson;

I still get the following error

Error:(5, 23) error: package com.google.gson does not exist

example from my app's build.gradle

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

and my settings.gradle

include 'gson:2.7'

Am I missing something?

like image 922
Leah Busch Avatar asked Jan 17 '18 18:01

Leah Busch


1 Answers

Open your project. Go to File -> Project Structure... Click on app in the Modules section and switch to the Dependencies tab. Click on the plus icon in the top right corner and select Library dependency. Select the entry for the GSON library from the list and hit OK twice. (Note: the search bar didn't work for me)

Then you are able to use the library just like you described in your question:
import com.google.gson.Gson;

Note that after adding the library your project will do a gradle sync which may take a couple of minutes.

like image 58
jemand771 Avatar answered Nov 15 '22 04:11

jemand771