android studio cannot resolve import org.json.JSONObject

I used libgdx to build my project and I am having issues using the JSONObject class. When I add import org.json.JSONObject, it says it cannot resolve. How do I add that library to my project?

Here is what I have tried without success:

  1. I downloaded the json-simple-1.1.jar and put it in core/build/libs folder. Could not use either.
  2. When browsing the tree in Android Studio as "Packages" dropdown, I can see the classes I want under "Core -> Libraries -> org -> json" but I cannot add them to my project. I get a "cannot refractor, class is in a jar file" error.

Is there something I have not tried yet to solve this issue? I feel I will run into this again as I try to use other external libraries.

Thank you.


If you are using LibGdx, it not comes with a Gradle setup making multy project builds streamlined.

Please look here:

You need to add compile 'org.json:json:20160212' to your top build.gradle, like:

dependencies {
   compile 'org.json:json:20160212'

Need Your Help

Defining the character encoding of a JavaScript source file

javascript unicode encoding

I would like to print a status message to my German users, which contains umlauts (ä/ü/ö). I also would like them be in the source file rather than having to download and parse some extra file just...