创建和使用“通用平台” Android 中的 jar - 什么有效?
它将我拥有的应用程序细分为“平台”和“应用程序”层,以便我可以将平台作为 jar 分发给合作伙伴使用 - 同时保护我的 IP。
我现在有两个 Eclipse 项目。 Building 无法将任何资源编译到 jar 中,因此我将所有资源引用移至应用程序项目中(平台项目 gen/ 目录为空)。我编译了平台,然后手动使用 jdk 将其打包,将该 jar 导入到应用程序项目中,在应用程序项目中标记要导出的 jar,并成功编译并安装了一个测试应用程序:
public class NotifyService extends Service {
...
@Override
public void onStart(Intent intent, int startId) {
myNotify(intent.getIntExtra(EXTRA_ICON),...));
}
private void myNotify(int iconResource, String s1, String s2, String s3) {
Context c = getApplicationContext();
if (H.VERBOSE) Log.d(TAG, "myNotify()"); //$NON-NLS-1$
Notification n = new Notification(iconResource, s1, currentTime);
Intent nextStep = new Intent(Intent.ACTION_VIEW,Uri));
PendingIntent pending = PendingIntent.getActivity(c, 0, nextStep, 0);
n.setLatestEventInfo(c, s2, s3, pending);
mgr.notify(1, n);
}...
测试活动按预期启动,我从此服务获取 LogCat() 消息。但没有显示通知,也没有记录错误 - 它只是静默。 ...
无论如何,我希望合作伙伴应用程序能够利用我的平台,该平台连接到服务、内容提供商、网络和作品。有人提供一些指导吗?
更新!
哈...典型...当我将所有资源从我的平台移到我的应用程序中时,我没有正确地将这些资源从应用程序层传递下来。因此,我给出的代码示例没有错误。当然,使用意图而不是链接可以将“传递的参数”与“预期的参数”解耦 - 并且编译器不会抱怨。使用修正后的应用程序,这是可行的。
虽然我认为创建一个二进制分发平台并不罕见,但我没有找到太多关于它的文档,所以当我打开大门时,我会继续添加任何重要的发现......希望它对某人有用。
It am sub-dividing an app I have into "platform" and "app" layers so that I can distribute the platform as a jar for use by partners - while protecting my IP.
I now have two Eclipse projects. Building has no ability to compile any resources into a jar, so I moved all resource references into the app project (the platform project gen/ directory is empty). I compiled the platform and then manually used the jdk to to jar it, imported that jar into the app project, marked the jar for export in the app project, and successfully compiled and installed a test app:
public class NotifyService extends Service {
...
@Override
public void onStart(Intent intent, int startId) {
myNotify(intent.getIntExtra(EXTRA_ICON),...));
}
private void myNotify(int iconResource, String s1, String s2, String s3) {
Context c = getApplicationContext();
if (H.VERBOSE) Log.d(TAG, "myNotify()"); //$NON-NLS-1$
Notification n = new Notification(iconResource, s1, currentTime);
Intent nextStep = new Intent(Intent.ACTION_VIEW,Uri));
PendingIntent pending = PendingIntent.getActivity(c, 0, nextStep, 0);
n.setLatestEventInfo(c, s2, s3, pending);
mgr.notify(1, n);
}...
The test activity launches as expected and I get the LogCat() message from this service. But no notification is shown and no error is logged - its just silent. ...
Anyway, I want partner apps to make use of my platform which connects to services, content providers, the web, the works. Anyone offer some guidance?
UPDATE!
Hah... typical... when I moved all the resources out of my platform and into my app I did not properly pass these down from the app layer. Thus, the code example I gave had no error. Using an intent rather than linking decouples "arguments passed" from "arguments expected" of course - and the compiler does not complain. With a corrected app, this works.
Though I'd think creating a binary distribution platform is not uncommon, I'm not finding much doc on it so I'll keep adding any significant findings as I open the doors ... hope it's of use to someone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该看看“图书馆项目”的概念。
使用库项目
[编辑]
@DJC - 我明白了......在这种情况下我建议查看 AndEngine 项目。该项目的输出是一个 JAR,然后在 AndEngineExamples 项目(使用它的示例应用程序)中使用。
AndEngine - 独立库,作为 JAR 分发
AndEngineExamples - 示例应用程序,使用 AndEngine JAR
You should look at the concept of a "Library project".
Working with Library Projects
[Edit]
@DJC - I see...in that case I would suggest looking at the AndEngine project. The output of that project is a JAR which is then used in the AndEngineExamples project (an example app that consumes it).
AndEngine - Standalone library, distributed as a JAR
AndEngineExamples - Examples app, which consumes the AndEngine JAR
考虑使用parcels,它就像一个Jar,只是它是android特有的。我对它们没有太多经验,但我认为它们在重用活动、视图和事物方面非常强大。
Look into using parcels, its like a Jar only its android specific. I don't have much experience with them but I think they are pretty powerful in terms of re-using activities and views and things.