简体   繁体   English

如何维护应用程序的付费和免费版本

[英]How to maintain a paid and free version of an app

I have built a free version of a game app which is now on the market with a name like com.mycompany.myfreegame. 我已经建立了一个游戏应用程序的免费版本,现在市场上有一个像com.mycompany.myfreegame这样的名字。 Now I want to make a paid version. 现在我想制作一个付费版本。 There will no doubt be tweaks and bug-fixes to both versions required for years to come so I want to encapsulate the encoding of the free vs paid information in as compact a way possible so that I can essentially fix bugs in both versions simultaneously. 毫无疑问,对于未来几年所需的两个版本都将进行调整和错误修复,因此我想以尽可能紧凑的方式封装免费与付费信息的编码,以便我可以同时修复两个版本中的错误。

If the entirety of the differences between the two versions was handled at runtime then I could set a single flag in the source code and that would be the end of the problem. 如果在运行时处理了两个版本之间的全部差异,那么我可以在源代码中设置一个标志,这将是问题的结束。 Unfortunately there are two other things to consider, 不幸的是还有两件事需要考虑,

  1. The name of the package needs to be different between the two versions. 两个版本之间的包名称需要不同。
  2. Some xml needs to be different. 有些xml需要不同。 For example the free version needs linear Layouts for holding ads, the paid version does not. 例如,免费版本需要线性布局来保存广告,而付费版本则不需要。

What is the simplest way to achieve this goal? 实现这一目标的最简单方法是什么?

I think the first approach I'd try is using 3 projects in Eclipse: one for either version of the game, and a library project with all of the shared code. 我认为我尝试的第一种方法是在Eclipse中使用3个项目:一个用于任一版本的游戏,另一个用于包含所有共享代码的库项目。 The library project would be where all the code for your core gameplay goes, and the version specific projects manage loading different layouts, putting ads in the free version, and adding levels/features/hats to the paid version. 图书馆项目将是您的核心游戏玩法的所有代码,并且特定于版本的项目管理加载不同的布局,将广告放入免费版本,以及向付费版本添加级别/功能/帽子。

You might be able to accomplish your goal of a single code base with a compiler flag using an ant task, but that's beyond me. 您可以使用ant任务使用编译器标志来实现单个代码库的目标,但这超出了我的范围。

I think what you're looking for is a Library Project http://developer.android.com/guide/developing/projects/index.html#LibraryProjects 我认为您正在寻找的是图书馆项目http://developer.android.com/guide/developing/projects/index.html#LibraryProjects

From that web page: 从该网页:

If you are creating an application that exists in both free and paid versions. You move the part of the application that is common to both versions into a library project. The two dependent projects, with their different package names, will reference the library project and provide only the difference between the two application versions.

Another question, very similar to this one, seems to have a decent discussion and answer: Multiple Apps with a shared code base 另一个与此非常相似的问题似乎有一个不错的讨论和答案: 具有共享代码库的多个应用程序

Edit: Here is a link on how to implement a library project. 编辑:这是一个如何实现库项目的链接。 http://developer.android.com/guide/developing/projects/projects-eclipse.html http://developer.android.com/guide/developing/projects/projects-eclipse.html

In regards to different versions being slightly different, a library project can accomodate. 对于略有不同的不同版本,图书馆项目可以容纳。 The library project is built first, then the parent (the project that uses the library) is built last and they are merged together. 首先构建库项目,然后最后构建父项(使用该库的项目)并将它们合并在一起。 Both projects can define the same resource identifiers and the project built last (parent project), gets priority (overwrites). 两个项目都可以定义相同的资源标识符和最后构建的项目(父项目),获得优先级(覆盖)。 So essentially, you can override strings/layouts (possibly more, not sure?) in the parent/calling application. 基本上,您可以在父/调用应用程序中覆盖字符串/布局(可能更多,不确定?)。

For example: Say you have two projects, free and paid.You could create a string with a default implementation (free version) and override it in your paid version (parent app). 例如:假设您有两个项目,免费和付费。您可以使用默认实现(免费版本)创建一个字符串,并在付费版本(父应用程序)中覆盖它。

Code in shared libraries Strings.xml file: 共享库中的代码Strings.xml文件:

<string name="AppName">My Application (Free)</string>

Code in parent app Strings.xml file: 父应用程序Strings.xml文件中的代码:

<string name="AppName">My Application Premium</string>

I would go with Maven . 我会和Maven一起去。 You can define a parent project with three sub-projects, say: 您可以使用三个子项目定义父项目,例如:

  • Common 共同
  • Paid 付费
  • Free 自由

Maven allows to have different configuration files, while having the same code base. Maven允许拥有不同的配置文件,同时具有相同的代码库。

For example, I currently have a project where two databases are used, so all the app config files remain on a common project, where the database configuration files and classes remain on each project folder. 例如,我目前有一个项目,其中使用了两个数据库,因此所有应用程序配置文件都保留在一个公共项目中,其中数据库配置文件和类保留在每个项目文件夹中。 When I do a build in the parent, every child project is built, unit tests passed, etc... 当我在父项目中进行构建时,每个子项目都会构建,单元测试通过等等......

Moreover, this is only one of the thousand advantages of maven! 而且,这只是maven的千种优势之一!

EDIT: I just found out, you have an android-plugin for maven, with cool features also 编辑:我刚刚发现,你有一个maven的android-plugin ,还有酷炫的功能

May be the best way now is to use Android Studio + gradle. 可能是现在最好的方法是使用Android Studio + gradle。 This case allows to build both paid and free versions with one command in console. 这种情况允许在控制台中使用一个命令构建付费和免费版本。 More details are in this post: https://stackoverflow.com/a/17286142/1705370 更多细节在这篇文章中: https//stackoverflow.com/a/17286142/1705370

I think you are looking for something similar to this: 我想你正在寻找类似的东西:

Multiple Android Application Package .apk files from single source code 单个源代码中的多个Android应用程序包.apk文件

Basically, the easiest approach here is to have two different manifest files and two different main activities and switch the compilation using Ant, though the latter is optional. 基本上,这里最简单的方法是使用两个不同的清单文件和两个不同的主要活动,并使用Ant切换编译,尽管后者是可选的。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM