如何在 Android 中包含 Spongy Castle JAR?
显然 Spongy Castle 是使用完整版 Bouncy Castle 的 Android 替代方案。
然而,在导入 jar 时,我遇到了各种“无法解析”错误,因为它依赖于 Android 中未包含的包,主要是 javax.mail、javax.activation 和 javax.awt.datatransfer。
那么解决这个问题的最佳方法是什么?对此问题的回复和 这表示这些包根本不应该使用,并且这个流行问题不'甚至不考虑寻找一种恢复 AWT 的方法。那么海绵城堡是如何依赖他们的呢? 人们正在使用 Spongy Castle,对吗?
Apparently Spongy Castle is the Android alternative to using a full version of Bouncy Castle.
However, on importing the jar I'm getting all kinds of "cannot be resolved" errors because it relies on packages not included with Android, primarily javax.mail, javax.activation, and javax.awt.datatransfer.
So what's the best way around this? Responses to this question and this indicate those packages shouldn't be used at all, and this popular question doesn't even consider finding a way to get AWT back. So how is Spongy Castle relying on them? People are using Spongy Castle, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 gradle,那么您只需在
build.gradle
文件中指定依赖项,如下所示:您可以找到库的最新版本此处。
不要忘记将其作为安全提供程序插入到您的应用程序中。
If you are using gradle, then you can just specify your dependencies in
build.gradle
file like this:You can find out the latest version of the library here.
Don't forget to insert it as a security provider in your app.
这是如何在项目中包含 Spongy Castle 的两个非常简单的示例:
自 v1.47 起,Spongy Castle 已被分成单独的子 jar,这些子 jar 完全镜像匹配的 Bouncy Castle 工件(例如
sc-light-jdk15on.jar
、scpg-jdk15on.jar
等),并且务必确保包含全部您正在做的事情所需的海绵城堡罐子。有关依赖项的完整信息可以在以下位置找到:
http://rtyley.github.com/spongycastle/#downloads< /a>
至少您需要
sc-light-jdk15on.jar
(基本轻量级 API 实现),可能还需要scprov-jdk15on.jar
( JCE 轻量级 API 的包装器)。如果您使用 Maven,那么所有这些依赖关系管理的事情都会为您处理好。您在
javax.mail
、javax.activation
等上描述的有问题的依赖项表明您可能选择了不正确的 jar(例如 every-single-library-component ) ,而不是“核心提供者”) - 因为scprov-jdk15on
jar 肯定不有任何这些奇怪的依赖项,并且在 Android 上运行得很好。(免责声明,我是 Spongy Castle 的维护者,但我也收到了大量其他用户的成功报告!)
These are two very simple examples of how to include Spongy Castle in a project:
Since v1.47, Spongy Castle has been split into separate sub-jars that exactly mirror the matching Bouncy Castle artifacts (eg
sc-light-jdk15on.jar
,scpg-jdk15on.jar
, etc), and it is important to ensure you include all the Spongy Castle jars required for what you're doing.Full information on dependencies can be found at:
http://rtyley.github.com/spongycastle/#downloads
At minimum you'll need the
sc-light-jdk15on.jar
(the base lightweight-API implementation) and probablyscprov-jdk15on.jar
(the JCE wrapper around the lightweight-API). If you're using Maven then all this dependency-management stuff is taken care of for you.The problematic dependencies you describe on
javax.mail
,javax.activation
, etc, indicate that you might have chosen an incorrect jar (e.g. the every-single-library-component one, rather than the 'core provider' one) - as thescprov-jdk15on
jar definitely doesn't have any of those weird dependencies, and runs happily on Android.(disclaimer, I'm the maintainer of Spongy Castle, but I've had plenty of success reports from other users too!)
同时BouncyCastle可以直接使用。在后来的 Android 版本中,内部 BC 包名称已更改,至少包名称冲突不再是问题,但仍然存在问题。有关解决方案,请查看以下内容:https://stackoverflow.com/a/57897224/3351474
In the meanwhile BouncyCastle can be used directly. In later Android versions the internal BC package name has changed and at least the package name collision is not the problem anymore, but there are still issues. For a solution look at this: https://stackoverflow.com/a/57897224/3351474