〖Android〗ant build android project, setting android.jar precedence

最近公司的一个项目中,新增了classes.jar包,与android.jar有冲突,必须得在加载android.jar前行加载classes.jar;

在持续集成环境中须使用ant编译,classes.jar放在libs/目录中,被加载的优先级是最低的,导致一些方法Method不能调用,也使得工程编译不过通过;

所以现在是classes.jar放在与AndroidManifest.xml同级的目录中,现在写一个custom_rules.xml以最优先加载classes.jar再加载android.jar;

<?xml version="1.0" encoding="UTF-8"?>
<!--
    scue:
      classes.jar 与 android.jar 有冲突,应先加载 classes.jar
      分析${sdk.dir}/tools/ant/build.xml得,应修改project.target.class.path
-->
<project name="custom_rules">
    <!--
    scue:
      -pre-build,编译前执行删除libs/classes.jar文件
    -->
    <target name='-pre-build'>
        <echo message="DELETE: libs/classes.jar"></echo>
        <delete>
            <fileset dir="libs" includes="**/classes.jar"/>
        </delete>
    </target>
    <target name="-pre-compile">
        <echo message="CLASSPATH.OLD=${toString:project.target.class.path}"></echo>
        <path id="project.target.class.path">
        <pathelement location="classes.jar"></pathelement>
        <pathelement location="${sdk.dir}/platforms/android-15/android.jar"></pathelement>
        </path>
        <echo message="CLASSPATH.NEW=${toString:project.target.class.path}"></echo>
    </target>
    <!--
    scue:
      -post-build,编译后执行拷贝classes.jar > libs/classes.jar文件
    -->
    <target name='-post-build'>
        <echo message="COPY: classes.jar --> libs/classes.jar"></echo>
        <copyfile src="classes.jar" dest="libs/classes.jar"/>
    </target>
</project>

把custom_rules.xml放在与AndroidManifest.xml同级目录即可,然后 ant debug,Enjoy!

你可能感兴趣的:(android)