build.xml和project_name.xml的区别

6
我是一个有帮助的助手,以下是您需要翻译的内容:

我已经连续几个小时试图了解Android的构建过程。

我正在使用IntelliJ Idea for Android(这是一个非常好的工具)。 我在IntelliJ中打开了一个名为“Hello Android”的测试项目。 该项目有一个名为 build.xml 的文件,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloAndroid" default="help">

    <!-- The local.properties file is created and updated by the 'android' tool.
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" />

    <!-- The ant.properties file can be created by you. It is only edited by the
         'android' tool to add properties to it.
         This is the place to change some Ant specific build properties.
         Here are some properties you may want to change/update:

         source.dir
             The name of the source directory. Default is 'src'.
         out.dir
             The name of the output directory. Default is 'bin'.

         For other overridable properties, look at the beginning of the rules
         files in the SDK, at tools/ant/build.xml

         Properties related to the SDK location or the project target should
         be updated using the 'android' tool with the 'update' action.

         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems.

         -->
    <property file="ant.properties" />

    <!-- if sdk.dir was not set from one of the property file, then
         get it from the ANDROID_HOME env var.
         This must be done before we load project.properties since
         the proguard config can use sdk.dir -->
    <property environment="env" />
    <condition property="sdk.dir" value="${env.ANDROID_HOME}">
        <isset property="env.ANDROID_HOME" />
    </condition>

    <!-- The project.properties file is created and updated by the 'android'
         tool, as well as ADT.

         This contains project specific properties such as project target, and library
         dependencies. Lower level build properties are stored in ant.properties
         (or in .classpath for Eclipse projects).

         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems. -->
    <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 the ANDROID_HOME environment variable."
            unless="sdk.dir"
    />

    <!--
        Import per project custom build rules if present at the root of the project.
        This is the place to put custom intermediary targets such as:
            -pre-build
            -pre-compile
            -post-compile (This is typically used for code obfuscation.
                           Compiled code location: ${out.classes.absolute.dir}
                           If this is not done in place, override ${out.dex.input.absolute.dir})
            -post-package
            -post-build
            -pre-clean
    -->
    <import file="custom_rules.xml" optional="true" />

    <!-- Import the actual build file.

         To customize existing targets, there are two options:
         - Customize only one target:
             - copy/paste the target into this file, *before* the
               <import> task.
             - customize it to your needs.
         - Customize the whole content of build.xml
             - copy/paste the content of the rules files (minus the top node)
               into this file, replacing the <import> task.
             - customize to your needs.

         ***********************
         ****** IMPORTANT ******
         ***********************
         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
         in order to avoid having your file be overridden by tools such as "android update project"
    -->
    <!-- version-tag: 1 -->
    <import file="${sdk.dir}/tools/ant/build.xml" />

</project>

然后我在IntelliJ Idea中进行了以下操作:Build -> Generate Ant Build并选择了以下选项:
  1. 生成多文件ant构建
  2. 输出文件名:helloandroid
  3. 启用UI表单编译
  4. 使用来自项目文件的JSDK定义
这将导致创建三个附加文件:
  1. helloandroid.properties
  2. helloandroid.xml
  3. module_helloandroid.xml
helloandroid.properties
path.variable.maven_repository=C\:\\Users\\abc\\.m2\\repository
jdk.home.android_4.1_platform=C\:/Program Files (x86)/Android/android-sdk

helloandroid.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloAndroid" default="help">

    <!-- The local.properties file is created and updated by the 'android' tool.
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" />

    <!-- The ant.properties file can be created by you. It is only edited by the
         'android' tool to add properties to it.
         This is the place to change some Ant specific build properties.
         Here are some properties you may want to change/update:

         source.dir
             The name of the source directory. Default is 'src'.
         out.dir
             The name of the output directory. Default is 'bin'.

         For other overridable properties, look at the beginning of the rules
         files in the SDK, at tools/ant/build.xml

         Properties related to the SDK location or the project target should
         be updated using the 'android' tool with the 'update' action.

         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems.

         -->
    <property file="ant.properties" />

    <!-- if sdk.dir was not set from one of the property file, then
         get it from the ANDROID_HOME env var.
         This must be done before we load project.properties since
         the proguard config can use sdk.dir -->
    <property environment="env" />
    <condition property="sdk.dir" value="${env.ANDROID_HOME}">
        <isset property="env.ANDROID_HOME" />
    </condition>

    <!-- The project.properties file is created and updated by the 'android'
         tool, as well as ADT.

         This contains project specific properties such as project target, and library
         dependencies. Lower level build properties are stored in ant.properties
         (or in .classpath for Eclipse projects).

         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems. -->
    <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 the ANDROID_HOME environment variable."
            unless="sdk.dir"
    />

    <!--
        Import per project custom build rules if present at the root of the project.
        This is the place to put custom intermediary targets such as:
            -pre-build
            -pre-compile
            -post-compile (This is typically used for code obfuscation.
                           Compiled code location: ${out.classes.absolute.dir}
                           If this is not done in place, override ${out.dex.input.absolute.dir})
            -post-package
            -post-build
            -pre-clean
    -->
    <import file="custom_rules.xml" optional="true" />

    <!-- Import the actual build file.

         To customize existing targets, there are two options:
         - Customize only one target:
             - copy/paste the target into this file, *before* the
               <import> task.
             - customize it to your needs.
         - Customize the whole content of build.xml
             - copy/paste the content of the rules files (minus the top node)
               into this file, replacing the <import> task.
             - customize to your needs.

         ***********************
         ****** IMPORTANT ******
         ***********************
         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
         in order to avoid having your file be overridden by tools such as "android update project"
    -->
    <!-- version-tag: 1 -->
    <import file="${sdk.dir}/tools/ant/build.xml" />

</project>

module_helloandroid.xml

<copy todir="${helloandroid.output.dir}">
  <fileset dir="${module.helloandroid.basedir}/src">
    <patternset refid="compiler.resources"/>
    <type type="file"/>
    <patternset refid="excluded.from.compilation.helloandroid"/>
  </fileset>
  <fileset dir="${module.helloandroid.basedir}/gen">
    <patternset refid="compiler.resources"/>
    <type type="file"/>
    <patternset refid="excluded.from.compilation.helloandroid"/>
  </fileset>
</copy>

我的问题

  1. 为什么我们有不同的 build.xml 和 helloandroid.xml 以及其他两个文件?
  2. 这些文件可以在构建过程中使用吗?
  3. 我们可以编辑这些文件以添加更多的 Ant 构建脚本吗?
  4. 为什么 build.xml 在 env.ANDROID_HOME 处显示错误?
  5. 为什么 helloandroid.xml 在 jdk.home.1.6 处显示错误?
1个回答

2
  1. 构建文件可以包含其他构建文件,这是一种常见的做法。你的项目中的 helloandroid.xml 文件与 build.xml 文件完全相同,你可以修改任何一个并且舍弃另一个。 build.xml 文件是 Ant 的首选约定。你的属性文件仅用于设置属性,而模块文件似乎没有被调用,但可能存在以便您可以将其包含并按照其指定进行文件复制。

  2. 是的,只需包含它们即可。 helloandroid.properties 文件可以用来代替对通用 project.properties 文件的调用,或者您可以保留原样。

  3. 是的,请编辑它们,尽管它们应该足以轻松开始。

  4. 看起来您的 ANDROID_HOME 环境变量尚未设置。您可以通过 IntelliJ 进行设置,但我建议在操作系统级别上进行设置。

  5. 看起来您的 JAVA_HOME 环境变量尚未设置。您可以通过 IntelliJ 进行设置,但我建议在操作系统级别上进行设置。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接