且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

管理 Android 应用程序商店(谷歌/亚马逊/等)的代码/构建?

更新时间:2022-12-21 15:03:38

在最新版本的 ADT(版本 17)中很容易做到,但我确实发现它使编译时间更长:

It's quite easy to do in the newest versions of ADT (version 17), though I do find it makes compilation a bit longer:

  1. 创建一个新的 Android 项目 (proj-A)
  2. 转到 Project->Properties,选择 Android,然后选中Is Library"
  3. 将所有常用代码移至 proj-A,导入所有必要的库
  4. 为 Google Play 创建一个新的 Android 项目 (proj-B)
  5. 转到 Project->Properties,选择 Android,然后将 Proj-A 添加到 Library
  6. 对亚马逊版本重复 #4&5
  1. Create a new Android project (proj-A)
  2. Go to Project->Properties, select Android, and check "Is Library"
  3. Move all your common code to proj-A, import all the necessary libraries
  4. Create a new Android project for Google Play (proj-B)
  5. Go to Project->Properties, select Android, and add Proj-A to the Library
  6. Repeat #4&5 for the Amazon version

如果您有一些变量应该为每个子项目设置不同的(即布尔值 GOOGLE_PLAY_VERSION 以启用 Google Play 特定功能),您必须创建另一个项目来包含这些值,因为您不能拥有引用一个的项目 -另一个以循环方式.您可以通过添加以下步骤来解决此问题:

If you have some variables that should be set differently for each sub project (i.e. boolean GOOGLE_PLAY_VERSION to enable Google Play specific functions), you have to create another project to contain these values since you can't have projects that reference one-another in a circular fashion. You can solve this by adding the following steps:

  1. 将所有子项目特定变量拉入一个或多个仅用作这些变量的容器的类
  2. 创建一个虚拟"Java 项目(虚拟)
  3. 配置 proj-A 以添加一个新的 Source 链接到 dummy
  4. 的 bin 目录
  5. 在具有项目特定更改的每个子项目中添加配置类
  6. 利润!
  1. Pull all of your sub-project specific variables into one or more Classes that just serves as container(s) for these variables
  2. Create a "dummy" Java project (dummy)
  3. Config proj-A to add a new Source link to the bin directory of dummy
  4. Add the config Classes in each sub-project with project-specific changes
  5. Profits!

注意dummy中的变量不要设为final,否则会覆盖子项目的设置.

Note that the variables in dummy should not be set as final, otherwise it will override sub-project's setting.

这看起来像是很多前期工作,但就版本控制而言,对我来说效果很好.

This may seem like quite a bit of up-front work, but has worked quite well for me as far as version control goes.

现在随着 Google 转向 Android Studio &Gradle,如果您要支持多个 APK,***开始一个新项目,请参阅 Android 开发站点的 使用 Gradle 构建您的项目#使用构建变体.在决定之前评估该选项绝对没有坏处.

Now with Google's move to Android Studio & Gradle, it may be better to move to that if you are starting a new project if you want to support multiple APKs, see Android dev site's Building Your Project with Gradle#Work with build variants. It definitely doesn't hurt to evaluate that option before deciding.