Android custom build using Ant

后端 未结 3 1134
陌清茗
陌清茗 2021-01-02 06:43

These 4 files (build.xml, local.properties, projects.properties, proguard.cfg) are auto-generated when running:

android update project --name TestApp --t

相关标签:
3条回答
  • 2021-01-02 07:05

    In build.xml itself, it tells you how to do this. See the following comment from the file:

    <!--
    
        ***********************
        ****** 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 -->
    
    0 讨论(0)
  • 2021-01-02 07:15

    Maybe you can check the answer to this question:

    Does the ADT plugin automatically create an ant build file?

    in the answer there is a paragraph saying...

    Alternatively, you can just copy the build.xml template directly from $ANDROID_HOME/tools/lib/build.template then just change the project name.

    Modify this file and run the commands to see if it works.

    Update

    Also check "Customizing the build" of this article: http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html

    0 讨论(0)
  • 2021-01-02 07:25

    The build.xml as generated by the android tool (at least when using Android SDK r20) contains this piece of code:

    <!--
        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" />
    

    So what I do to create additional targets or customize existing targets is to create a custom_rules.xml file with these new targets. Note that in my tests the targets needed to be nested in a <project> tag, so simply copy the first two lines of your generated build.xml to custom_rules.xml, and don't forget about the closing </project> tag in the end. As custom_rules.xml will not be overwritten by android update your changes will be persistent and can be checked into your SCM tool of choice.

    0 讨论(0)
提交回复
热议问题