简体   繁体   中英

Using Ant how can I dex a directory of jars?

I have a directory full of jars (felix bundles). I want to iterate through all of these jars and create dex'd versions. My intent is to deploy each of these dex'd jars as standalone apk's since they are bundles. Feel free to straighten me out if I am approaching this from the wrong direction.

This first part is just to try and create a corresponding .dex file for each jar. However when I run this I am getting a "no resources specified" error coming out of Ant.

Is this the right approach, or is there a simpler approach to just input a jar and output a dex'd version of that jar? The ${file} is valid as it is spitting out the name of the file in the echo command.

<target name="dexBundles" description="Run dex on all the bundles">
    <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/libs/ant-contrib.jar" />
    <echo>Starting</echo>
    <for param="file">
        <path>
            <fileset dir="${pre.dex.dir}">
                <include name="**/*.jar" />
            </fileset>
        </path>
        <sequential>
            <echo message="@{file}" />
            <echo>Converting jar file @{file} into ${post.dex.dir}/@{file}.class...</echo>
              <apply executable="${dx}" failonerror="true" parallel="true" verbose="true">
                <arg value="--dex" />
                <arg value="--output=${post.dex.dir}/${file}.dex" />
                <arg path="@{file}" />
              </apply>
        </sequential>
    </for>
    <echo>Finished</echo>
</target>

Give this a go:

    <target name="dexBundles" description="Run dex on all the bundles">
        <apply executable="${exec.dx}" dest="${post.dex.dir}/" parallel="false">
            <arg value="--dex"/>
            <arg value="--output="/>
            <targetfile/>
            <srcfile/>
            <fileset dir="${pre.dex.dir}" includes="**/*.jar"/>
            <mapper type="glob" from="*.jar" to="*.dex"/>
        </apply>
    </target>

It looks like the ant apply task allows you to iterate over a file set without need for ant-contrib (specifically that page has an example that looks for *.c in a directory, compiles them, and renames them to *.o in a specified directory that should be directly applicable). Unfortunately, it looks like you'll lose the traceability provided by your echo messages.

For the record, I believe the error message is actually being generated by dx.bat not ant directly, but I am not certain, and I don't know why.

Hope that helps.

see the document of the "Ant apply task" ,it's said:“ At least one fileset or filelist is required

so,this line "no resources specified" is printed to notify u that to write some fileset or filelist.....

use "exec" instead.

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