Android:如何在使用同一证书签名的项目之间共享代码

发布于 2024-08-30 02:42:45 字数 313 浏览 3 评论 0原文

在 Android 有关代码签名的文档中,我们可以阅读:“ 通过使用同一证书签署多个应用程序并使用基于签名的权限检查,您的应用程序可以以安全的方式共享代码和数据。

这种代码共享到底是如何实现的完毕?是否可以发布主应用程序和多个可交换插件,然后在运行时发现它们?源代码是什么样的?与从/到不同 APK 包的“标准”意图调用相比,有哪些优势?

In Android documentation concerning code signing we can read: "By signing multiple applications with the same certificate and using signature-based permissions checks, your applications can share code and data in a secure manner."

How exactly such code sharing can be done? Is it possible to release main application and multiple exchangeable plugins then discover them at runtime? What does source code looks like and what are advantages over "standard" intents calls from/to different APK packages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的黑色迷你裙 2024-09-06 02:42:45

使用 Context.createPackageContext() 实例化您感兴趣的另一个 .apk 的包。如果它使用与您相同的证书进行签名,并且您都使用相同的共享用户 ID,那么您可以使用该标志来加载其代码到您的进程中,允许您从上下文中获取类加载器并实例化您想要的任何类。

否则,如果它们没有相同的签名并且显式使用相同的共享使用ID,则只能加载其资源。

请注意,一旦应用程序上市,您就无法更改该应用程序的共享用户 ID(更改为其他内容或在拥有和不拥有共享用户 ID 之间切换)。

Use Context.createPackageContext() to instantiate a package for another .apk you are interested in. If it is signed with the same cert as yours, AND you are both using the same shared user ID, then you can use the flag to load its code into your process, allowing you to get the ClassLoader from the context and instantiate whatever classes you want.

Otherwise, if they are not signed the same and explicitly using the same shared used ID, you can only load its resources.

Please note that you can not change the shared user ID for an application (to something else or moving between having and not having a shared user ID) once that application is on market.

耳钉梦 2024-09-06 02:42:45

假设您要调用动态加载类的公共函数。使用以下代码片段:

Context friendContext = this.createPackageContext("packageName", Context.CONTEXT_INCLUDE_CODE);
Class friendClass = friendContext.getClassLoader().loadClass("packageName.className");
Class noparams[] = {}; //say the function (functionName) required no inputs
friendClass.getMethod("functionName", noparams).invoke(friendClass.newInstance(), null);

Say you want to call a public function of the dynamically loaded class. Use the following code snippet:

Context friendContext = this.createPackageContext("packageName", Context.CONTEXT_INCLUDE_CODE);
Class friendClass = friendContext.getClassLoader().loadClass("packageName.className");
Class noparams[] = {}; //say the function (functionName) required no inputs
friendClass.getMethod("functionName", noparams).invoke(friendClass.newInstance(), null);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文