【问题标题】:Replacing color.xml and images during build在构建期间替换 color.xml 和图像
【发布时间】:2014-04-02 08:04:49
【问题描述】:

我使用 Maven 构建 Android 应用程序。我必须使用相同的代码库构建不同的应用程序。但每个都包含不同的主题(color.xml 中的按钮和页面颜色以及可绘制文件夹中的彩色图标)。每次发布每个应用程序之前,我都会手动替换它们。

您能否建议一种使用工具的简单方法?或者是否可以通过 Maven 通过提供所需的目录路径来替换 color.xml 和图像?

我在整个互联网上进行了搜索,但我无法找到这个特定问题的答案。

【问题讨论】:

    标签: android xml maven maven-plugin


    【解决方案1】:

    您可以使用maven profilesresource plugin 来做到这一点

    您需要在pom.xml 中定义配置文件:

    </profiles>
        <profile>
            <id>variantA</id>
            <build>
                <!-- custom conf for variant A -->
            </build>
        </profile>
        </profile>
        <profile>
            <id>variantB</id>
            <build>
                <!-- custom conf for variant B -->
            </build>
        </profile>
    </profiles>
    

    然后使用所需的配置文件调用您的构建:

    mvn clean install -P variantB
    

    还可以使用资源插件覆盖整个 color.xml 文件(在此示例中,在文件夹 src/templates/resVariantA 中创建 color.xml 文件):

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
            <execution>
                <phase>initialize</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.basedir}/res</outputDirectory>
                    <overwrite>true</overwrite>
                    <resources>
                        <resource>
                            <directory>${project.basedir}/src/templates/resVariantA</directory>
                            <targetPath>${project.basedir}/res</targetPath>
                            <filtering>true</filtering>
                         </resource>
                     </resources>
                 </configuration>
             </execution>
        </executions>
    </plugin>
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2014-08-24
      • 2023-04-10
      • 2016-08-05
      • 2018-12-11
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多