Android dex: method ID not in [0, 0xffff]: 65536问题

引用ruboto-irb  的build.xml,项目地址 https://github.com/ruboto/ruboto-irb/blob/master/build.xml

https://github.com/ruboto/ruboto-irb/blob/master/build.xml



原文内容

<?xml version="1.0" encoding="UTF-8"?>
<project name="IRB" default="help">

    <!-- The local.properties file is created and updated by the 'android' tool.
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" />

    <!-- The ant.properties file can be created by you. It is only edited by the
         'android' tool to add properties to it.
         This is the place to change some Ant specific build properties.
         Here are some properties you may want to change/update:
         source.dir
             The name of the source directory. Default is 'src'.
         out.dir
             The name of the output directory. Default is 'bin'.
         For other overridable properties, look at the beginning of the rules
         files in the SDK, at tools/ant/build.xml
         Properties related to the SDK location or the project target should
         be updated using the 'android' tool with the 'update' action.
         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems.
         -->
    <property file="ant.properties" />

    <!-- if sdk.dir was not set from one of the property file, then
         get it from the ANDROID_HOME env var.
         This must be done before we load project.properties since
         the proguard config can use sdk.dir -->
    <property environment="env" />
    <condition property="sdk.dir" value="${env.ANDROID_HOME}">
        <isset property="env.ANDROID_HOME" />
    </condition>

    <!-- The project.properties file is created and updated by the 'android'
         tool, as well as ADT.
         This contains project specific properties such as project target, and library
         dependencies. Lower level build properties are stored in ant.properties
         (or in .classpath for Eclipse projects).
         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems. -->
    <loadproperties srcFile="project.properties" />

    <!-- quick check on sdk.dir -->
    <fail
            message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
            unless="sdk.dir"
    />

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

    <!-- Import the actual build file.
         To customize existing targets, there are two options:
         - Customize only one target:
             - copy/paste the target into this file, *before* the
               <import> task.
             - customize it to your needs.
         - Customize the whole content of build.xml
             - copy/paste the content of the rules files (minus the top node)
               into this file, replacing the <import> task.
             - customize to your needs.
         ***********************
         ****** 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 -->
    <import file="${sdk.dir}/tools/ant/build.xml" />

    <!-- BEGIN added by Ruboto -->
    <property name="second_dex_file" value="${out.absolute.dir}/classes2.dex" />

    <macrodef name="multi-dex-helper">
      <element name="external-libs" optional="yes" />
      <sequential>
            <union id="out.dex.jar.input.ref.union">
                <resources refid="out.dex.jar.input.ref"/>
            </union>
            <if>
                <condition>
                    <uptodate targetfile="${out.absolute.dir}/classes.dex" >
                        <srcfiles dir="${out.classes.absolute.dir}" includes="**/*.class"/>
                        <srcresources refid="out.dex.jar.input.ref.union"/>
                    </uptodate>
                </condition>
                <then>
                    <echo>Java classes and jars are unchanged.</echo>
                </then>
                <else>
                    <echo>Converting compiled files and external libraries into ${out.absolute.dir} (multi-dex)</echo>
                    <delete file="${out.absolute.dir}/classes2.dex"/>
                    <echo>Dexing ${out.classes.absolute.dir} and ${toString:out.dex.jar.input.ref}</echo>
                    <apply executable="${dx}" failonerror="true" parallel="true">
                        <arg value="--dex" />
                        <arg value="--multi-dex" />
                        <arg value="--output=${out.absolute.dir}" />
                        <arg line="${jumbo.option}" />
                        <arg line="${verbose.option}" />
                        <arg path="${out.classes.absolute.dir}" />
                        <path refid="out.dex.jar.input.ref" />
                        <external-libs />
                    </apply>
                    <sleep seconds="1"/>
                </else>
            </if>
      </sequential>
    </macrodef>

    <macrodef name="dex-helper">
      <element name="external-libs" optional="yes" />
      <attribute name="nolocals" default="false" />
      <sequential>
          <!-- sets the primary input for dex. If a pre-dex task sets it to
               something else this has no effect -->
        <property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" />

        <!-- set the secondary dx input: the project (and library) jar files
             If a pre-dex task sets it to something else this has no effect -->
        <if>
          <condition>
            <isreference refid="out.dex.jar.input.ref" />
          </condition>
          <else>
            <path id="out.dex.jar.input.ref">
              <path refid="project.all.jars.path" />
            </path>
          </else>
        </if>
        <condition property="verbose.option" value="--verbose" else="">
          <istrue value="${verbose}" />
        </condition>
        <condition property="jumbo.option" value="--force-jumbo" else="">
          <istrue value="${dex.force.jumbo}" />
        </condition>

        <if>
          <condition>
            <not>
              <available file="${second_dex_file}" />
            </not>
          </condition>
          <then>
            <!-- Regular DEX process.  We would prefer to use the Android SDK
                 ANT target, but we need to detect the "use multidex" error.
                 https://android.googlesource.com/platform/sdk/+/tools_r21.1/anttasks/src/com/android/ant/DexExecTask.java
            -->
            <mapper id="pre-dex-mapper" type="glob" from="libs/*.jar" to="bin/dexedLibs/*-dexed.jar"/>


            <!-- FIXME(uwe): Output something about what we are doing -->

            <apply executable="${dx}" failonerror="true" parallel="false" dest="${out.dexed.absolute.dir}" relative="true">
                        <arg value="--dex" />
                        <arg value="--output" />
                        <targetfile/>
                        <arg line="${jumbo.option}" />
                        <arg line="${verbose.option}" />
                        <fileset dir="." includes="libs/*" />
                        <external-libs />
                        <mapper refid="pre-dex-mapper"/>
            </apply>

            <apply executable="${dx}" resultproperty="dex.merge.result" outputproperty="dex.merge.output" parallel="true">
                <arg value="--dex" />
                <arg value="--output=${intermediate.dex.file}" />
                <arg line="${jumbo.option}" />
                <arg line="${verbose.option}" />
                <arg path="${out.classes.absolute.dir}" />
                <fileset dir="${out.dexed.absolute.dir}" includes="*-dexed.jar" />
                <external-libs />
            </apply>

            <if>
              <condition>
                <contains string="${dex.merge.output}" substring="method ID not in [0, 0xffff]: 65536"/>
              </condition>
              <then>
                <echo message="The package contains too many methods.  Switching to multi-dex build." />
                <multi-dex-helper>
                  <external-libs>
                    <external-libs/>
                  </external-libs>
                </multi-dex-helper>
              </then>
              <else>
                <echo message="${dex.merge.output}"/>
                <fail status="${dex.merge.result}">
                  <condition>
                    <not>
                      <equals arg1="${dex.merge.result}" arg2="0"/>
                    </not>
                  </condition>
                </fail>
              </else>
            </if>

          </then>
          <else>
            <multi-dex-helper>
              <external-libs>
                <external-libs/>
              </external-libs>
            </multi-dex-helper>
          </else>
        </if>
      </sequential>
    </macrodef>

    <!-- This is copied directly from <android-sdk>/tools/ant/build.xml,
         just added the "-post-package-resources" dependency -->
    <target name="-package" depends="-dex, -package-resources, -post-package-resources">
        <!-- only package apk if *not* a library project -->
        <do-only-if-not-library elseText="Library project: do not package apk..." >
            <if condition="${build.is.instrumented}">
                <then>
                    <package-helper>
                        <extra-jars>
                            <!-- Injected from external file -->
                            <jarfile path="${emma.dir}/emma_device.jar" />
                        </extra-jars>
                    </package-helper>
                </then>
                <else>
                    <package-helper />
                </else>
            </if>
        </do-only-if-not-library>
    </target>

    <target name="-post-package-resources">
        <!-- FIXME(uwe):  This is hardcoded for one extra dex file.
                          It should iterate over all classes?.dex files -->
        <property name="second_dex_path" value="assets/classes2.jar" />
        <property name="second_dex_jar" value="${out.dexed.absolute.dir}/${second_dex_path}" />
        <property name="second_dex_copy" value="${out.dexed.absolute.dir}/classes.dex" />
        <if>
            <condition>
              <and>
                <available file="${second_dex_file}" />
                <or>
                  <not>
                    <uptodate srcfile="${second_dex_file}" targetfile="${out.absolute.dir}/${resource.package.file.name}" />
                  </not>
                  <uptodate srcfile="${out.absolute.dir}/${resource.package.file.name}" targetfile="${out.absolute.dir}/${resource.package.file.name}.d" />
                </or>
              </and>
            </condition>
            <then>
                <echo>Adding ${second_dex_path} to ${resource.package.file.name}</echo>
                <exec executable="aapt" dir="${out.dexed.absolute.dir}">
                  <arg line='remove -v "${out.absolute.dir}/${resource.package.file.name}" ${second_dex_path}'/>
                </exec>
                <copy file="${second_dex_file}" tofile="${second_dex_copy}"/>
                <mkdir dir="${out.dexed.absolute.dir}/assets"/>
                <zip destfile="${second_dex_jar}" basedir="${out.dexed.absolute.dir}" includes="classes.dex" />
                <delete file="${second_dex_copy}"/>

                <!-- FIXME(uwe): Use zip instead of aapt? -->
                <exec executable="aapt" dir="${out.dexed.absolute.dir}" failonerror="true">
                  <arg line='add -v "${out.absolute.dir}/${resource.package.file.name}" ${second_dex_path}'/>
                </exec>
                <!-- EMXIF -->

            </then>
        </if>
    </target>
    <!-- END added by Ruboto -->


</project>

你可能感兴趣的:(打包异常)