构建多(测试/生产)的Andr​​oid的APK的在Eclipse版本版本、测试、Andr、oid

2023-09-06 13:19:59 作者:向日葵de微笑

我在寻找优化生成相同的Andr​​oid应用程序略有不同的APK,唯一的不同是它的使用(开发/分期/生产)的HTTP API服务器。

I'm looking to optimize generating of slightly different APKs of the same Android app, the only difference being the http API server it's using (dev/staging/prod).

在理想情况下,我只希望我的Eclipse构建2的APK,一是与督促服务器和一个与开发的。

Ideally, I'd just want my Eclipse to build 2 APKs, one with the prod server and one with the dev one.

我甚至用具有2运行配置还算可以,但我一直无法弄清楚如何将参数传递给应用程序,并从code阅读。

I'm even OK with having 2 Run configurations, but I haven't been able to figure out how to pass parameters to the app and read them from the code.

我想要的目标1.5,顺便说一句,我想使用Eclipse自动生成工具,所以我在寻找最通用的解决方案。

I want to target 1.5, BTW, and I'd like to use Eclipse auto-build tools, so I'm looking for the most generic solution.

感谢你。

推荐答案

我想使用Ant构建脚本将是最简单的解决方案。 Eclipse支持Ant构建,这样你就可以在Eclipse中运行ant命令。

I think using ant build script would be the easiest solution. Eclipse supports ant build, so you can run ant command in eclipse.

您可以解决你的问题,蚂蚁是这样的。

You can solve your problem with ant like this.

prepare两个XML的Andr​​oid资源文件。 建立包资源#1 覆盖资源#1的资源#2 内容 在建一个包

XML会是这样的:

资源#1:

<resources>
    <string name="target">dev</string>
</resources>

资源#2:

<resources>
    <string name="target">staging</string>
</resources>

和Ant脚本会是这样的:

and ant script would be like this:

<project>
  <target name="build_all">
     <copy file="res1.xml" to="res/values/target.xml"/>
     <ant antfile="build.xml" target="debug"/>
     <copy file="res2.xml" to="res/values/target.xml"/>
     <ant antfile="build.xml" target="debug"/>
  </target>
</project>