android studio cannot resolve import org.json.JSONObject

橙三吉。 提交于 2019-12-01 14:07:28

问题


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 import.org.json.simple.JSONObject 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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!