Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't android find com.google.gson.Gson

I'm trying to use GSON in my project, but my application is crashing, with logcat saying that com.google.gson.Gson cannot be found. I've put import com.google.gson.Gson on my class files, I have gson in my package explorer, and added it by Right click -> build path -> add libraries. It also shows up in Project->properties->java build path->libraries tab->gson. What have I done wrong?

like image 345
Douglas Dlutz Avatar asked Apr 17 '11 14:04

Douglas Dlutz


People also ask

What is GSON Library in Android?

Google's Gson library provides a powerful framework for converting between JSON strings and Java objects. This library helps to avoid needing to write boilerplate code to parse JSON responses yourself. It can be used with any networking library, including the Android Async HTTP Client and OkHttp.


1 Answers

What worked for me: Check the checkbox next to the lib (gson-2.0.jar) in: 'Project Properties' -> 'Java Build Path' -> 'Order and Export' tab. Then do a clean/build.

This adds the exported=true attribute to the classpath entry

<classpathentry exported="true" kind="lib" path="libs/gson-2.0.jar"/> 
like image 130
Erik B Avatar answered Oct 06 '22 04:10

Erik B