管理 Android 应用程序商店(谷歌/亚马逊/等)的代码/构建? [英] Manage code/build for Android app stores (Google/Amazon/etc)?

查看:42
本文介绍了管理 Android 应用程序商店(谷歌/亚马逊/等)的代码/构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要从 Android Market(现在是 Google Play)下载的 Android 应用.我们对源代码进行了一些调整,并将其提交给亚马逊应用商店,以了解它的吸引力.我现在正在寻找一种可持续的方式,从通用代码库进行开发,然后进行构建,以便我可以向其中一个/两个提交.

I have an Android app that's downloaded primarily from Android Market (now, Google Play). We made a few tweaks to the source and also submitted to the Amazon App Store to see what sort of traction it gets. I'm now looking for a sustainable way to develop from a common code base and yet build so that I can submit to either/both.

亚马逊的商店对可用的 API 有一些限制,因此我想有条件地删除/修改该版本的功能.由于 Java 不支持传统的条件编译,而且在 Eclipse 中有条件地包含文件似乎不是微不足道的(甚至可能吗?),我想问问其他人正在做什么来解决这个问题.

Amazon's store has some restrictions about available APIs, and hence I'd like to conditionally remove/modify features from that version. Since Java doesn't support traditional conditional compilation, and conditionally including files in Eclipse doesn't seem trivial (is it even possible?), I wanted to ask what others are doing to solve this.

诚然,我不是 Eclipse/Java 专家,所以请随时向我学习.

Admittedly, I'm no Eclipse/Java expert so feel free to school me.

我在解决方案中寻找什么:

What I'm looking for in a solution:

  • 使用 Eclipse 构建/调试.
  • 静态代码文件,通过环境/设置切换来控制要构建的内容.
  • 代码中没有重复的代码或条件逻辑来选择运行时的代码流

这是您专门为 Android 应用或其他基于 Java/Eclipse 的项目解决的问题吗?建议从哪里开始?

Is this something you've solved for Android apps specifically, or for other Java/Eclipse based projects? Suggestions for where to begin?

推荐答案

在最新版本的 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.

这篇关于管理 Android 应用程序商店(谷歌/亚马逊/等)的代码/构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆