2012-07-21 66 views
1

我建立在Eclipse的Android应用程序,并具有基于相同的代码库,一个“伦敦”一个和“英国”一两个类似的应用程序。要构建每个应用程序,我只需重命名主包并在Application类中更改一个静态int。该应用程序使用此INT的值,以显示右UI,限制用户行为等有条件包括安卓(Eclipse的)资源基于项目

我有两个图标文件,一个用于每个应用程序:

  • RES /抽拉-HDPI/icon_london.png
  • RES /提拉 - 华电国际/ icon_uk.png

有什么办法来有条件地使用取决于某种项目配置设置的应用程序和活动正确的图标文件?否则,项目维护会增加,因为每次代码库变化时我都必须更改清单。

<application 
    android:icon="@drawable/icon_london" 
    ... 
    > 

    <activity 
     android:name="com.company.MainActivity" 
     android:logo="@drawable/icon_london" 
     > 
    </activity> 

...等等,对于所有的活动。

回答

1

我也有类似的问题,并在构建我custon Ant脚本来构建应用程序结束了。您可以运行宏或正则表达式来分配一个资源或另一个资源。

编辑:

首先,添加的build.xml到项目:

打开一个命令提示符并导航到你的项目的目录:

android update project --path 

然后,可以覆盖现有的build.xml,如下所示。

注:此Ant脚本只是一个例子,我没有测试它:

<?xml version="1.0" encoding="UTF-8"?> 
<project name="Example" default="help"> 
    <property file="local.properties" /> 
    <property file="ant.properties" /> 

    <loadproperties srcFile="project.properties" /> 

    <!-- quick check on sdk.dir --> 
    <fail 
      message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var" 
      unless="sdk.dir"/> 

    <!-- IMPORT ANT?S BUILD.XML --> 
    <import file="${sdk.dir}/tools/ant/build.xml" /> 

    <property name="app.icon"  value="${icon}" /> 
    <property name="icon.file"  location="res/drawable/icon.png" /> 

    <target name="test-release"> 
     <antcall target="test-pre-release" /> 
     <antcall target="release" /> 
    </target> 

    <target name="test-pre-release"> 
     <copy file="${app.icon}" tofile="${icon.file}" overwrite="true"/> 
    </target> 

</project> 

然后,构建该项目使用自定义图标,打开命令提示符,然后转到项目目录:

CALL ant -f build.xml test-release -Dicon=path/to/your/icon.png 

如上所述,这是一个非常基本的例子。要建立一个良好的脚本,你必须了解一点的Ant语法,但它并不难。

+0

我以前从未使用过蚂蚁;可以把它集成到Eclipse的工作流程,或者我需要用我想要重新构建和分发每次命令行? – 2012-07-21 14:43:10

+0

蚂蚁来构建应用程序。您可以检查SDK位置内的现有Ant脚本(例如... \ android-sdk \ tools \ ant \ build.xml)。而且,为了建立你自己的...有很多教程可以解释这个过程。例如。 http://www.enterra-inc.com/techzone/using_ant_android_applications_building/ – 2012-07-21 14:47:39

+0

您能否在您的答案中添加一个Ant脚本示例以说明您是如何实现这一目标的? – 2012-07-21 14:59:01