问题
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:
- I downloaded the
json-simple-1.1.jar
and put it in core/build/libs folder. Could not useimport.org.json.simple.JSONObject
either. - 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.
回答1:
If you are using LibGdx, it not comes with a Gradle setup making multy project builds streamlined.
Please look here: http://mvnrepository.com/artifact/org.json/json/.
You need to add compile 'org.json:json:20160212'
to your top build.gradle
, like:
dependencies {
compile 'org.json:json:20160212'
}
来源:https://stackoverflow.com/questions/28588802/android-studio-cannot-resolve-import-org-json-jsonobject