更改或升级内置的org.json库是可能的,还是个好主意?
我的应用程序在很大程度上取决于JSON库org.json.*
.该软件包内置于Android标准库中,这是我不知道的,因为我也将其包含在源代码树中.
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.
我需要使用内置软件包不支持的函数(JSONArray.remove
),而该函数位于org.json
的源分发罐中(我包含在我的项目中).因此,发生的事情是,所有内容都会编译并生成.全部,但在运行时出现 java.lang.NoSuchMethodError:org.json.JSONArray.remove .
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.
我的问题是,如何告诉eclipse或Android使用源树中的org.json.*而不是其内置版本?
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?
还有一个子问题:这是个好主意吗?内置的JSON包可能相对于官方源代码发行版具有本机级别的改进吗?
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?
我的问题是,如何告诉eclipse或Android使用源树中的org.json.*而不是其内置版本?
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.
欢迎您使用 jarjar
或类似工具移动您将org.json
类的副本复制到新程序包中.或者,找到一个更好的JSON库-那里有很多.
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.