维护应用程序的免费版和专业版

发布于 2024-08-26 14:16:47 字数 588 浏览 13 评论 0原文

我想为 Android 创建应用程序的 PRO 版本,并且想知道如何构建我的存储库。

据我所知,我有一个主干和特色分支。我想将专业版放在另一个分支中,但也许有更好的方法?例如,也许我应该创建两个分支 - 一个用于免费版本,另一个用于专业版本?

专业版将具有附加功能并且无广告,因此例如。我不想在专业版中包含 AdMob 库。

对于在这种情况下构建存储库的最佳方法,您有什么经验或建议吗?

编辑: 我想我已经在这个线程中找到了最好的解决方案(对于我的应用程序): http://groups.google.com/group/android-developers/browse_thread/thread/4ad3d67f735f16d7/948b4f9eee2490a3

那里讨论的技巧是让另一个应用程序仅用于解锁 PRO 功能实际应用。解锁应用程序在市场上付费,实际应用程序仅检查设备上是否存在该应用程序。

I want to create a PRO version of my application for Android and was wondering how to structure my repository.

For know I have a trunk and feature branches. I'd like to put a pro version in another branch but maybe there is a better way? For example, maybe I should create two branches - one for free version, the other for pro?

Pro version will have additional features and will be ads-free, so eg. I don't want to include AdMob libraries in the pro version.

Do you have any experience or suggestions as to what would be the best way to structure the repository in this case?

EDIT:
I think I've found the best solution (for my app) in this thread: http://groups.google.com/group/android-developers/browse_thread/thread/4ad3d67f735f16d7/948b4f9eee2490a3

The trick discussed there is about having another application that only serves the purpose of unlocking PRO functionality in the actual application. The unlocking app is paid in the market and the actual app merely checks for the existence of it on the device.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

素年丶 2024-09-02 14:16:47

我知道您已经做出了决定,但我还有另一个建议可能对其他人有帮助。

我使用 git 作为我的存储库。创建和维护分支非常容易。我有我的主“专业”存储库和一个“免费”分支。我对 master 进行了所有代码更改。我的“免费”分支仅因触发“免费”行为的任何更改而有所不同。
每当我完成对代码的更改时,我都会将其提交到主分支,然后切换到自由分支并使用“rebase”命令将其赶上主分支。

它会回滚使其表现为“免费”版本的更改,应用我对 master 所做的更改,然后重新应用“免费”更改。

我不必维护两个版本。我不必记住切换某些开关,或来回进行相同的更改。它非常光滑,而且我比第二个触发专业行为的应用程序更喜欢它,因为我可以删除相关版本不需要的库。

I know you have already made your decision, but I have another suggestion that might help others.

I use git for my repository. Creating and maintaining branches is very easy. I have my master "pro" repository, and a "free" branch. I make all code changes to the master. My "free" branch only differs by whatever changes trigger the "free" behavior.
Whenever I'm done making changes to the code, I commit it to the master branch, then switch over to the free branch and use the "rebase" command to catch it up with the master.

It rolls back the change that makes it behave as the "free" version, applies the changes I made to master, then re-applies the "free" changes.

I don't have to maintain two versions. I don't have to remember to toggle some switch, or make the same changes back and forth. It's pretty slick, and I like it better than a second app that triggers the pro behavior because I can strip out libraries that aren't needed for the version in question.

野稚 2024-09-02 14:16:47

我建议不要维护两个分支,而是使用运行时或编译时开关来禁用免费版本的 PRO 功能。您甚至可以在构建时删除不需要的 DLL。

维护两个分支意味着在两个地方解决问题,随着分支不可避免地出现分歧,这将变得更加严重。

I would suggest not maintaining two branches, but have either runtime or compile time switches to disable the PRO functionality for the free version. You could even remove not required DLL's when building.

Maintaining two branches means fixing problems in two places, which will become more of a problem as the branches inevitably diverge.

断舍离 2024-09-02 14:16:47

我在 Eclipse 中找到了一种简单的方法来做到这一点。当我发现它时,我很惊讶它是多么容易。

  1. 在 com.app.free 的项目属性中,检查“Is Library”是否为 true(在更改此设置之前,您必须至少编译该项目一次,否则您会收到一条错误,指出无法编译库项目,如果您确实收到此错误)取消选中它,编译,然后重新选中
  2. 创建新项目 com.app.pro
  3. 在项目的 android 部分的项目设置中添加 com.app.free 项目作为库
  4. 在 com.app 中创建新类 MyApplication .pro 和扩展应用程序
  5. 覆盖 onCreate() 注意:对于那些复制/粘贴者来说,这与活动的 onCreate(Bundle savingInstanceState) 捆绑包不同,您必须删除 Bundle 参数,因为这是一个应用程序而不是活动。然后
  6. 添加或设置将在验证方法中读取的静态变量以验证许可证 EX: IS_PRO = true; 然后,如果 IS_PRO 为 true,则验证方法将返回 true 将
  7. 清单内容复制到 com 。 .app.pro
  8. 将 android:name="MyApplication " 添加到 com.app.pro 清单中的应用程序标记中,
  9. 在所有活动的名称属性前面附加 com.app.free 。 (这使应用程序知道您的活动可以在免费版本的库包中找到) EX: android:name=".MainActivity" => android:name="com.app.free.MainActivity"
  10. 现在编译,您就有了专业版

此方法假设您正在使用全局验证方法。例如,我创建了一个类,将用户连接到我的域上托管的数据库,该数据库确定用户首次安装应用程序的时间。对于任何仅限专业人士的活动,我会检查 LicenseClass.isValidLicense() ,它会比较日期,如果少于所需的天数,则返回 true。在 isValidLicense() 函数中,我检查 Application.IS_PRO 是否设置为 true,如果设置为 true,则返回 true。

因此,现在您可以进行尽可能多的更改,无论频率如何,您所要做的就是重新编译两者。唯一要记住的是,您在 com.app.free 清单中所做的任何更改都必须反映在专业版中。但任何应用程序都是如此,因为 Android 应用程序要求您声明无论如何都将使用哪些活动。

注意:您可以删除项目创建时自动生成的所有资产和资源(但不要删除 res 文件夹本身),因为它们不会被使用。另外,唯一需要的类文件是步骤 3 中的 MyApplication 文件。这意味着您也可以删除自动生成的 MainActivity.class,因为它也从未使用过。您还可以删除专业版中未使用的任何标签。 EX:我有一个 BuyPro 活动,如果验证失败,该活动就会打开。由于验证在专业版中永远不会失败,因此不需要。当然,所有这些删除都是可选的,只是让您知道我学到了什么。

缺点:到目前为止我发现的唯一缺点是您不能将 switch 语句与资源变量一起使用,因为它们不再是常量。因此,当您将项目用作库时,如果您在专业版本中声明了同名的变量,则您在 strings.xml 文件中创建的任何变量都会被自动覆盖。对我来说这不是一个缺点,因为我不喜欢在 java 中使用 switch 状态,因为它们限制你只能切换 int 类型并且它们需要常量值。这意味着在 java 中我通常必须有 if ... else 语句。另外,如果您将光标放在 switch 关键字上并按 Ctrl+1,然后单击“转换为 if else”,Eclipse 实际上会帮助转换 switch 语句。另外,我发现覆盖资源非常有用,因为您可以执行诸如将 app_name 从“app free”更改为“app pro”之类的操作,或者只需在所在位置创建新版本即可上传新的可绘制对象(例如应用程序图标)它存在于免费应用程序中。例如:如果 res/values/string.xml 包含 100 个字符串变量,但您在专业版本中需要或想要更改的只是 app_name,只需重新创建 res/values/string.xml (不是复制)并添加 app_name 变量。现在,免费版本中的 app_name 变量将被覆盖,这意味着专业版本中的 string.xml 文件只需要包含 1 个变量而不是 100,因为它是唯一发生更改的变量。简单易行。 :-)

编辑:我发现 eclipse 不允许导出 .apk 的库,因此在将其添加为专业版本中的库后,您必须取消选中免费版本中的“Is Library”选项。据我所知,这样做的唯一作用是导致 eclipse 不会警告您有关 switch 语句问题。除此之外它似乎工作得很好。

I found an easy way to do this in eclipse. I was quite surprised at how easy it was once I discovered it.

  1. In project properties for com.app.free check the "Is Library" as true (you must have compiled the project at least once before changing this otherwise you get an error saying that library projects cannot be compiled, if you do get this error simply un-check it, compile, then re-check.
  2. create new project com.app.pro
  3. add com.app.free project as a library in the project settings in the android section of the pro porject
  4. create new class MyApplication in com.app.pro and extend Application
  5. override onCreate() NOTE: For those fellow copy/paste'ers this is NOT the same as the onCreate(Bundle savedInstanceState) bundle of an activity. You must remove the Bundle argument as this is an application not an activity.
  6. Then add or set the static variable which will be read in the validation method to validate license. EX: IS_PRO = true; then validation method reads variable and returns true if IS_PRO is true.
  7. Copy manifest contents form com.app.free to com.app.pro
  8. add android:name="MyApplication " to the application tag in the com.app.pro manifest
  9. append com.app.free in front of name attribute for all activities. (this makes the application know that your activities are to be found in the library package which is the free version) EX: android:name=".MainActivity" => android:name="com.app.free.MainActivity"
  10. Now compile and you have a pro version

This method assumes you are using a global validation method. For example I created a class that connects users to a DB hosted on my domain which determines when the user first installed the app. For any pro only activities I check LicenseClass.isValidLicense() which compares dates and return true if its been less than the desired number of days. in the isValidLicense() function I check if Application.IS_PRO is set to true and return true if it is.

So now you can make as many changes however often and all you have to do is recompile both. The only thing to keep in mind is what ever changes you make in the com.app.free manifest have to be reflected in the pro. But this is the case with any application because android apps require you to declare which activities you are going to use no matter what.

NOTE: You may delete all assets and resources(dont't delete the res folder itself though) that are auto generated at project creation as they will not be used. Also, the only class file needed is the MyApplication file from step 3. Which means you may also delete the MainActivity.class that is auto generated as well since it is also never used. You may also remove any tags that are not used in the used in the pro version. EX: I have a BuyPro activity which opens if validation fails. Since validation will never fail in pro version it is not required. Of course all these deletions are optional just letting you know what I've learned.

CONS: The only con I found so far is that you can't use switch statements with your resource variables because they are no longer constants. So when you use a project as a library any variable you create in your strings.xml file for example are automatically overridden if you declare a variable of the same name in the pro version. For me this is not a con because I don't like using switch states in java because they limit you to switching on int type only and they require constant values. Which means in java I usually have to us if ... else staments anyway. Plus Eclipse will actually help convert switch statements if you put your cursor on the switch key word and press Ctrl+1 then click convert to if else. Also, I find it pretty useful that the resources are overridden because you can do things like change app_name from "app free" to "app pro" or upload a new drawable for say the app icon simply by creating the new version in the location where it exists in the free app. EX: if the res/values/string.xml contains say 100 string variables but all you need or want to change in the pro version is the app_name simply recreate the res/values/string.xml (NOT copy) and add the app_name variable. Now the app_name variable in the free version will be overridden which means the string.xml file in the pro version only needs to contain the 1 variable instead of 100 since its the only variable that changed. Easy Peasy. :-)

EDIT: I found out eclipse doesn't let yo export .apk's for libraries so you have to un-check the "Is Library" option in the free version after you've added it as a library in the pro version. As far as I can tell the only thing this does is causes eclipse not to warn you about the switch statement issue. Other than that it seems to work just fine.

花开半夏魅人心 2024-09-02 14:16:47

有一个带有 public static final boolean IS_PRO 的版本来确定免费/专业行为。

编辑:
包裹的事。假设您的所有类都位于 com.myapp.android.free 下。
然后,在 AndroidManifest.xml 中声明 package="com.myapp.android" 为付费版本,package="com.myapp.android.free" 为免费版本一个。
如果您使用活动、服务等的全名,则无需更改其他任何内容。

我不会费心从付费版本中删除未使用的库。如果这样做,您将必须手动执行此操作。

Have a single version with public static final boolean IS_PRO that would determine free/pro behavior.

EDIT:
The package thing. Say, all your classes reside under com.myapp.android.free.
Then, in AndroidManifest.xml you declare package="com.myapp.android" for the paid version and package="com.myapp.android.free" for the free one.
If you use full names for activities, services, etc., you won't have to change anything else.

I wouldn't bother removing unused libs from the paid version. If you do, you'll have to do this manually.

萌能量女王 2024-09-02 14:16:47

我认为要走的路是产品风味/构建变体。请参阅文档,以及此示例

I think the way to go is Product Flavors/build variants. See the documentation, and this example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文