Android:如何在使用相同证书签名的项目之间共享代码 [英] Android: how to share code between projects signed with the same certificate

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

问题描述

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

这样的代码共享究竟如何做呢?是否可以释放主应用程序和多个可交换插件,然后在运行时发现它们?

解决方案

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



否则,如果他们没有签名相同,明确使用相同的共享使用ID,您只能加载其资源。



请注意,您无法更改应用程序的共享用户ID(以其他方式或在有和没有共享用户ID)。


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?

解决方案

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆