在 Eclipse 中使用 Android 应用程序切换试用版和专业版:如何减轻痛苦?
我有一个 Android 应用程序,有两种形式:试用版和付费“专业”版。这两个版本在 Android Market 中共存,并且具有不同的包名称(我们将它们称为 com.app.Trial 和 com.app.pro)。他们共享相同的代码库。当我必须在 Eclispe 中的试用版和专业版之间切换时,每次编辑代码都必须花费不少于 20 分钟才能构建正确的版本。我的过程如下所示:
重命名 AndroidManifest.xml 中的包名称(同时重命名应用程序 versionName 和 versionCode)。
单击主包名称“com.app.pro”(如果 pro 是最新版本,现在我想进行试用版本)并选择“重构”->“重命名”(选中“更新引用”和“重命名子包”) )并让 Eclipse 进行重命名。
这之后是最困难的部分:在我的代码中,许多文件仍然导入“旧”包名称“com.app.pro”,而不是自动更改为“com.app.Trial”。在某些情况下,Eclipse 在重命名期间添加这些引用,没有明显的原因(给定的 Java 文件中没有对此特定包的引用)。我必须手动编辑所有实例。
我的问题是:
如何减少此过程的耗时?我还一直在使用 NetBeans,它对 #ifdefs(又名能力)提供方便的支持,这确实使构建之间的切换变得轻而易举。遗憾的是,Eclipse 不支持(至少没有内置支持)#ifdefs。
任何建议将不胜感激。
PS 作为参考,我正在使用 Eclipse Ganymede 版本 3.4.2,但也尝试了较新的版本,它的作用相同。
I have an application for Android which comes in two forms: a trial version and a paid "pro" version. The two versions coexists in Android Market and have different package names (let's call them com.app.trial and com.app.pro). They share the same codebase. When I have to switch between trial and pro builds in Eclispe, I have to spend no less than 20 minutes each time editing the code to make it build the correct version. My procedure looks like this:
Rename package name in AndroidManifest.xml (also rename app versionName, and versionCode).
Click on main package name "com.app.pro" (if pro was the lastest build and now I want to make a trial build) and select Refactor->Rename (check 'Update references' and 'Rename subpackages') and let Eclipse do the renaming.
After this comes the hard part: in my code many files still import the "old" package name, "com.app.pro" instead of being automatically changed to "com.app.trial". In some cases Eclipse adds those references during the renaming, for no apparent reasons (there are no references to this specific package from within a given Java file). I have to manually edit all the instances.
My question is:
How do I make this procedure less time consuming? I also have been using NetBeans where there's a handy support for #ifdefs (aka Abilities) which really makes switching between builds a breeze. Eclipse unfortunately has no support (at least no buil-in support) for #ifdefs.
Any suggestions would be greatly appreciated.
P.S. For the reference I am using Eclipse Ganymede version 3.4.2 but also tried a newer version, it does the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个很好的解决方案是将您的应用程序分成三个项目:
每个试用版和专业版将:
这样,构建试用版或专业版就像构建一个项目或另一个项目一样简单:无需更改任何内容!
一些可能有帮助的链接:
A great solution for this is to split your applications into three projects :
Each trial and pro version will :
With that, building the trial or the pro version is as simple as building one project, or the other : no need to change anything !
A couple of links that might help :