简体   繁体   中英

Adding external dependencies to ant project (IDEA Android project)

In the documentation to socket.io-java by nkzawa is mentioned that to add ant dependency should be used next snippet :

<dependency org="com.github.nkzawa" name="socket.io-client" rev="0.1.1-SNAPSHOT"> <artifact name="socket.io-client" type="jar" /> </dependency>

In which file and how I should include it? How I should compile my application after that?

为了使用ant管理依赖关系,您需要使用Ivy,但是我同意Bart Kiers的观点-切换到Gradle ,尤其是在您已经在使用IDEA的情况下。

The socket.io-client documentation is misleading. ANT has an extension called ivy for performing dependency management, but it is not bundled by default.

Once setup you can list your project's dependencies in an ivy.xml file or within your build.xml using the cachepath task:

<ivy:cachepath pathid="compile.path">
   <dependency org="com.github.nkzawa" name="socket.io-client" rev="0.1.1" />
</ivy:cachepath>

I have included a more complete example below. It details how to configure your ANT build to automatically setup ivy.

I am not an android programmer, so not able to recommend the best build tool. What I can say is that adding dependency management to your build process is a very good idea. ANT pre-dates more modern tools like Maven and Gradle that have this feature baked in.

Example

build.xml

<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ================
    Build properties
    ================
    -->
    <available classname="org.apache.ivy.Main" property="ivy.installed"/> 

    <!--
    ===========
    Build setup
    ===========
    -->
    <target name="install-ivy" description="Install ivy" unless="ivy.installed">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
        <fail message="Ivy has been installed. Run the build again"/>
    </target>

    <target name="resolve" depends="install-ivy" description="Use ivy to resolve classpaths">
        <ivy:cachepath pathid="compile.path">
           <dependency org="com.github.nkzawa" name="socket.io-client" rev="0.1.1" />
        </ivy:cachepath>
    </target>

    <!--
    ===============
    Compile targets
    ===============
    -->
    <target name="build" depends="resolve" description="Project build logic goes here">
       <javac .... classpathref="compile.path">
       </javac>

       ...
    </target>

    <!--
    ===============
    Clean-up targets
    ===============
    -->
    <target name="clean" description="Cleanup build files">
        <delete dir="build"/>
    </target>

    <target name="clean-all" depends="clean" description="Additionally purge ivy cache">
        <ivy:cleancache/>
    </target>

</project>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM