修改ant构建过程以构建android jar

时间:2017-08-17 16:33:52

标签: android command-line jar ant build

我继承了一个内部构建过程,它接受了一些c静态库和java包装类,构建过程使用apache ant命令行工具创建一个包含类的jar,这个jar用于使用静态库在Java SE甚至Android应用程序上。

我最近在包装类中添加了一些特定于android的函数,这导致ant构建失败,因为它只是为了从Java源创建jar而且在ant xml构建指令中只引用了jdk而不是android sdk。我的问题是如何修改现有的xml文件以允许从android源构建以生成可在Android上运行的jar存档。这是当前构建的xml。

    <?xml version="1.0" encoding="UTF-8"?>
<project name="identosjar" default="all">


  <property file="identosjar.properties"/>
  <!-- Uncomment the following property if no tests compilation is needed -->
  <!-- 
  <property name="skip.tests" value="true"/>
   -->

  <!-- Compiler options -->

  <property name="compiler.debug" value="on"/>
  <property name="compiler.generate.no.warnings" value="off"/>
  <property name="compiler.args" value=""/>
  <property name="compiler.max.memory" value="700m"/>
  <patternset id="ignored.files">
    <exclude name="**/*.hprof/**"/>
    <exclude name="**/*.pyc/**"/>
    <exclude name="**/*.pyo/**"/>
    <exclude name="**/*.rbc/**"/>
    <exclude name="**/*~/**"/>
    <exclude name="**/.DS_Store/**"/>
    <exclude name="**/.git/**"/>
    <exclude name="**/.hg/**"/>
    <exclude name="**/.svn/**"/>
    <exclude name="**/CVS/**"/>
    <exclude name="**/RCS/**"/>
    <exclude name="**/SCCS/**"/>
    <exclude name="**/__pycache__/**"/>
    <exclude name="**/_svn/**"/>
    <exclude name="**/rcs/**"/>
    <exclude name="**/vssver.scc/**"/>
    <exclude name="**/vssver2.scc/**"/>
  </patternset>
  <patternset id="library.patterns">
    <include name="*.war"/>
    <include name="*.swc"/>
    <include name="*.apk"/>
    <include name="*.zip"/>
    <include name="*.egg"/>
    <include name="*.ane"/>
    <include name="*.jar"/>
    <include name="*.ear"/>
  </patternset>
  <patternset id="compiler.resources">
    <exclude name="**/?*.java"/>
    <exclude name="**/?*.form"/>
    <exclude name="**/?*.class"/>
    <exclude name="**/?*.groovy"/>
    <exclude name="**/?*.scala"/>
    <exclude name="**/?*.flex"/>
    <exclude name="**/?*.kt"/>
    <exclude name="**/?*.clj"/>
    <exclude name="**/?*.aj"/>
  </patternset>

  <!-- JDK definitions -->

  <property name="jdk.bin.1.7" value="${jdk.home.1.7}/bin"/>
  <path id="jdk.classpath.1.7">
    <fileset dir="${jdk.home.1.7}">
      <include name="jre/lib/charsets.jar"/>
      <include name="jre/lib/deploy.jar"/>
      <include name="jre/lib/ext/dnsns.jar"/>
      <include name="jre/lib/ext/localedata.jar"/>
      <include name="jre/lib/ext/sunec.jar"/>
      <include name="jre/lib/ext/sunjce_provider.jar"/>
      <include name="jre/lib/ext/sunpkcs11.jar"/>
      <include name="jre/lib/ext/zipfs.jar"/>
      <include name="jre/lib/htmlconverter.jar"/>
      <include name="jre/lib/javaws.jar"/>
      <include name="jre/lib/jce.jar"/>
      <include name="jre/lib/jfr.jar"/>
      <include name="jre/lib/jfxrt.jar"/>
      <include name="jre/lib/jsse.jar"/>
      <include name="jre/lib/management-agent.jar"/>
      <include name="jre/lib/plugin.jar"/>
      <include name="jre/lib/resources.jar"/>
      <include name="jre/lib/rt.jar"/>
      <include name="lib/ant-javafx.jar"/>
      <include name="lib/dt.jar"/>
      <include name="lib/javafx-doclet.jar"/>
      <include name="lib/javafx-mx.jar"/>
      <include name="lib/jconsole.jar"/>
      <include name="lib/sa-jdi.jar"/>
      <include name="lib/tools.jar"/>
    </fileset>
  </path>

  <property name="project.jdk.home" value="${jdk.home.1.7}"/>
  <property name="project.jdk.bin" value="${jdk.bin.1.7}"/>
  <property name="project.jdk.classpath" value="jdk.classpath.1.7"/>

  <!-- Modules -->


  <!-- Module IdentosJar -->

  <dirname property="module.identosjar.basedir" file="${ant.file}"/>


  <property name="module.jdk.home.identosjar" value="${project.jdk.home}"/>
  <property name="module.jdk.bin.identosjar" value="${project.jdk.bin}"/>
  <property name="module.jdk.classpath.identosjar" value="${project.jdk.classpath}"/>

  <property name="compiler.args.identosjar" value="-encoding UTF-8 -source 1.7 -target 1.7 ${compiler.args}"/>

  <property name="identosjar.output.dir" value="${module.identosjar.basedir}/out/production/IdentosJar"/>
  <property name="identosjar.testoutput.dir" value="${module.identosjar.basedir}/out/test/IdentosJar"/>

  <path id="identosjar.module.bootclasspath">
    <!-- Paths to be included in compilation bootclasspath -->
  </path>

  <path id="identosjar.module.production.classpath">
    <path refid="${module.jdk.classpath.identosjar}"/>
  </path>

  <path id="identosjar.runtime.production.module.classpath">
    <pathelement location="${identosjar.output.dir}"/>
  </path>

  <path id="identosjar.module.classpath">
    <path refid="${module.jdk.classpath.identosjar}"/>
    <pathelement location="${identosjar.output.dir}"/>
  </path>

  <path id="identosjar.runtime.module.classpath">
    <pathelement location="${identosjar.testoutput.dir}"/>
    <pathelement location="${identosjar.output.dir}"/>
  </path>


  <patternset id="excluded.from.module.identosjar">
    <patternset refid="ignored.files"/>
  </patternset>

  <patternset id="excluded.from.compilation.identosjar">
    <patternset refid="excluded.from.module.identosjar"/>
  </patternset>

  <path id="identosjar.module.sourcepath">
    <dirset dir="${module.identosjar.basedir}">
      <include name="src"/>
    </dirset>
  </path>


  <target name="compile.module.identosjar" depends="compile.module.identosjar.production,compile.module.identosjar.tests" description="Compile module IdentosJar"/>

  <target name="compile.module.identosjar.production" description="Compile module IdentosJar; production classes">
    <mkdir dir="${identosjar.output.dir}"/>
    <javac destdir="${identosjar.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.identosjar}/javac">
      <compilerarg line="${compiler.args.identosjar}"/>
      <bootclasspath refid="identosjar.module.bootclasspath"/>
      <classpath refid="identosjar.module.production.classpath"/>
      <src refid="identosjar.module.sourcepath"/>
      <patternset refid="excluded.from.compilation.identosjar"/>
    </javac>

    <copy todir="${identosjar.output.dir}">
      <fileset dir="${module.identosjar.basedir}/src">
        <patternset refid="compiler.resources"/>
        <type type="file"/>
      </fileset>
    </copy>
  </target>

  <target name="compile.module.identosjar.tests" depends="compile.module.identosjar.production" description="compile module IdentosJar; test classes" unless="skip.tests"/>

  <target name="clean.module.identosjar" description="cleanup module">
    <delete dir="${identosjar.output.dir}"/>
    <delete dir="${identosjar.testoutput.dir}"/>
  </target>

  <target name="init" description="Build initialization">
    <!-- Perform any build initialization in this target -->
  </target>

  <target name="clean" depends="clean.module.identosjar" description="cleanup all"/>

  <target name="build.modules" depends="init, clean, compile.module.identosjar" description="build all modules"/>

  <target name="init.artifacts">
    <property name="artifacts.temp.dir" value="${basedir}/__artifacts_temp"/>
    <property name="artifact.output.identos" value="${basedir}/out/artifacts/identos"/>
    <mkdir dir="${artifacts.temp.dir}"/>
    <property name="temp.jar.path.identos.jar" value="${artifacts.temp.dir}/identos.jar"/>
  </target>

  <target name="artifact.identos" depends="init.artifacts, compile.module.identosjar" description="Build &#39;identos&#39; artifact">
    <property name="artifact.temp.output.identos" value="${artifacts.temp.dir}/identos"/>
    <mkdir dir="${artifact.temp.output.identos}"/>
    <jar destfile="${temp.jar.path.identos.jar}" duplicate="preserve" filesetmanifest="mergewithoutmain">
      <zipfileset dir="${identosjar.output.dir}"/>
    </jar>
    <copy file="${temp.jar.path.identos.jar}" tofile="${artifact.temp.output.identos}/identos.jar"/>
  </target>

  <target name="build.all.artifacts" depends="artifact.identos" description="Build all artifacts">
    <mkdir dir="${artifact.output.identos}"/>
    <copy todir="${artifact.output.identos}">
      <fileset dir="${artifact.temp.output.identos}"/>
    </copy>

    <!-- Delete temporary files -->
    <delete dir="${artifacts.temp.dir}"/>
  </target>

  <target name="all" depends="build.modules, build.all.artifacts" description="build all"/>
</project>

EDIT ant文件的名称是identosjar.xml,因此命令是

ant -buildfile identosjar.xml

另外,错误

compile.module.identosjar.production:     [mkdir]创建目录:/Users/samuel.oyediran/SDK/build/android-arm/package/out/production/IdentosJar     [javac] /Users/samuel.oyediran/SDK/build/android-arm/package/identosjar.xml:154:警告:&#39; includeantruntime&#39;没有设置,默认为build.sysclasspath = last;对于可重复的构建,设置为false     [javac]将12个源文件编译为/Users/samuel.oyediran/SDK/build/android-arm/package/out/production/IdentosJar     [javac] /Users/samuel.oyediran/SDK/build/android-arm/package/src/com/identos/Identos.java:4:错误:包android.content不存在     [javac] import android.content.Context;     [javac] ^     [javac] /Users/samuel.oyediran/SDK/build/android-arm/package/src/com/identos/Identos.java:29:错误:找不到符号     [javac] public int initialize(Context context,String appid,String clientkey,String version,boolean livemode,String filepath)     [javac] ^     [javac] symbol:class Context     [javac] location:class Identos     [javac] /Users/samuel.oyediran/SDK/build/android-arm/package/src/com/identos/PlatformVerificationManager.java:3:错误:包android.content不存在     [javac] import android.content.Context;     [javac] ^     [javac] /Users/samuel.oyediran/SDK/build/android-arm/package/src/com/identos/PlatformVerificationManager.java:4:错误:包android.content.pm不存在     [javac] import android.content.pm.ApplicationInfo;     [javac] ^     [javac] /Users/samuel.oyediran/SDK/build/android-arm/package/src/com/identos/PlatformVerificationManager.java:5:错误:包android.content.pm不存在     [javac] import android.content.pm.PackageInfo;     [javac] ^     [javac] /Users/samuel.oyediran/SDK/build/android-arm/package/src/com/identos/PlatformVerificationManager.java:6:错误:包android.content.pm不存在     [javac] import android.content.pm.PackageManager;

0 个答案:

没有答案