如何保持两个版本相同的Andr​​oid应用程序吗?

问题描述:

这是相当频繁,我们看到两个版本的Andr​​oid应用程序:付费版本和免费版本。我也在开发一个应用程序,想发布两个版本。什么是做到这一点的最好方法是什么?创建两个项目,并在两者之间复制文件似乎并没有在我心中的最佳方式。

It's quite often that we see two versions of an android app: a paid version and a free version. I'm also developing an app that would like to release two versions. What is the best way to do this? Creating two projects and copying files in between does not seem to be the best way in my mind.

更新:这个方法真的是唯一的好与Eclipse编译,由于Android Studio支持的建口味可正是这一点实现。

Update: This method is really only good for compiling with Eclipse, since Android Studio supports build flavors which can achieve exactly this.

虽然@ yorkw的和@ Nate的回答都不错,的是我因为用其简单的方法。从文章:

While @yorkw's and @Nate's answers are both good, this is the method I use due to its simplicity. From the article:

      
  • com.example.myapp - Android项目库 - 这是我的整个应用程序生命。所有的full和lite版本的功能。
  •   
  • com.example.myapp.full - Android应用程序项目 - 这是包含需要的只是完整版显卡和资源外壳。基本上这是一个超轻量级外壳。
  •   
  • com.example.myapp.lite - Android应用程序项目 - 这是一个包含什么,但所需的精简版版显卡和资源另一个shell。再次,它是一个超轻量级外壳。
  •   
  • com.example.myapp – Android Project Library - This is where my ENTIRE app lives. All the functionality for the FULL and LITE versions.
  • com.example.myapp.full - Android Application Project - This is a shell that contains graphics and resources needed for the full version only. Basically it’s a super lightweight shell.
  • com.example.myapp.lite - Android Application Project – This is another shell that contains nothing but graphics and resources needed for the lite version. Again, its a super lightweight shell.

我还留着在其中设置应用程序启动时,库类的静态变量 IS_PRO 。这应仅用于使用通知,警报等(例如要求用户升级到原)。

I also keep a static variable IS_PRO in a library class which is set when the app launches. This should be used only for notifications, alerts, and so on (such as asking the user to upgrade to pro).

不过,这种方法有一个缺点:您必须清理并重建随时库或资源被修改。此外,一定要阅读这个职位项目和库之间中的资源共享。

However, this method has one drawback: you must clean and rebuild any time the library or its resources are modified. Also be sure to read this post on sharing resources between a project and a library.