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

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

本文介绍了Android:如何在使用相同证书签名的项目之间共享代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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."

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

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?

推荐答案

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

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.

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

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

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

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.

这篇关于Android:如何在使用相同证书签名的项目之间共享代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 12:17