问题
My application depends a lot on the JSON library org.json.*
. This package is built-in into Android standard libraries, something I didn't know because I also included it in my source tree.
I need to use a function (JSONArray.remove
) that is not supported on the built-in package, while it is in the source distribution jar from org.json
(that I include in my project). So what happens is, everything compiles & all, but I get java.lang.NoSuchMethodError: org.json.JSONArray.remove at runtime.
My question is, how can I tell eclipse or Android to use the org.json.* from my source tree instead of its built-in version?
And a sub-question: Is it a good idea at all? May the built-in JSON package have native-level improvements or something like that vs. the official source code distribution?
回答1:
My question is, how can I tell eclipse or Android to use the org.json.* from my source tree instead of its built-in version?
You can't. You do not control the runtime classpath, and the firmware always wins.
You are welcome to use jarjar or a similar tool to move your copy of the org.json
classes into a new package. Or, find a better JSON library -- there's lots of them out there.
来源:https://stackoverflow.com/questions/20389105/changing-or-upgrading-built-in-org-json-libraries-is-possible-and-a-good-idea