java.lang.ArrayIndexOutOfBoundsException during Android project ant build
Recently, in order to overcome 64k method limitation by using custom class
loading :
http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html
I have the following Ant build file by taking from
https://code.google.com/p/android-custom-class-loading-sample/source/browse/trunk/android-custom-class-loading-sample/build.xml
I merely change the excluded library from com/example/dex/lib/** to
org/yccheok/jstock/lib/**
<?xml version="1.0" encoding="UTF-8"?>
<project name="secondary_dex_sample" default="help">
<property file="local.properties" />
<property file="ant.properties" />
<loadproperties srcFile="project.properties" />
<fail
message="sdk.dir is missing. Make sure to generate
local.properties using 'android update project' or to inject
it through an env var"
unless="sdk.dir"
/>
<!-- This is a modified version of the "dex-helper" macro. It added
the "input-dir" and
"output-dex-file" required attributes.
Configurable macro, which allows to pass as parameters input
directory,
output directory, output dex filename and external libraries to
dex (optional) -->
<macrodef name="dex-helper-mod">
<attribute name="input-dir" />
<attribute name="output-dex-file" />
<element name="external-libs" optional="yes" />
<element name="extra-parameters" optional="yes" />
<attribute name="nolocals" default="false" />
<sequential>
<!-- 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>
<echo>Converting compiled files and external libraries into
@{output-dex-file}...</echo>
<dex executable="${dx}"
output="@{output-dex-file}"
nolocals="@{nolocals}"
verbose="${verbose}">
<path path="@{input-dir}"/>
<path refid="out.dex.jar.input.ref" />
<external-libs />
</dex>
</sequential>
</macrodef>
<!-- This is a modified version of "-dex" target taken from
$SDK/tools/ant/main_rules.xml -->
<!-- Converts this project's .class files into .dex files -->
<target name="-dex" depends="-compile, -post-compile, -obfuscate"
unless="do.not.compile">
<if condition="${manifest.hasCode}">
<then>
<!-- Create staging directories to store .class files to
be converted to the -->
<!-- default dex and the secondary dex. -->
<mkdir dir="${out.classes.absolute.dir}.1"/>
<mkdir dir="${out.classes.absolute.dir}.2"/>
<!-- Primary dex to include everything but the concrete
library implementation. -->
<copy todir="${out.classes.absolute.dir}.1" >
<fileset dir="${out.classes.absolute.dir}" >
<exclude name="org/yccheok/jstock/lib/**" />
</fileset>
</copy>
<!-- Secondary dex to include the concrete library
implementation. -->
<copy todir="${out.classes.absolute.dir}.2" >
<fileset dir="${out.classes.absolute.dir}" >
<include name="org/yccheok/jstock/lib/*" />
</fileset>
</copy>
<!-- Compile .class files from the two stage directories
to the apppropriate dex files. -->
<dex-helper-mod input-dir="${out.classes.absolute.dir}.1"
output-dex-file="${out.absolute.dir}/${dex.file.name}" />
<mkdir dir="${out.absolute.dir}/secondary_dex_dir" />
<dex-helper-mod input-dir="${out.classes.absolute.dir}.2"
output-dex-file="${out.absolute.dir}/secondary_dex_dir/classes.dex"
/>
<!-- Jar the secondary dex file so it can be consumed by
the DexClassLoader. -->
<!-- Package the output in the assets directory of the
apk. -->
<jar destfile="${asset.absolute.dir}/secondary_dex.jar"
basedir="${out.absolute.dir}/secondary_dex_dir"
includes="classes.dex" />
</then>
<else>
<echo>hasCode = false. Skipping...</echo>
</else>
</if>
</target>
<!-- version-tag: custom -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
I run the ant command.
ant release -Dsdk.dir=c:\adt-bundle-windows-x86_64-20130717\sdk
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] Found 1 AIDL files.
BUILD FAILED
c:\adt-bundle-windows-x86_64-20130717\sdk\tools\ant\build.xml:649: The
following error occurred while executing this line:
c:\adt-bundle-windows-x86_64-20130717\sdk\tools\ant\build.xml:655:
java.lang.ArrayIndexOutOfBoundsException: 1
at
com.android.ant.DependencyGraph.parseDependencyFile(DependencyGraph.java:180)
at com.android.ant.DependencyGraph.<init>(DependencyGraph.java:54)
at
com.android.ant.MultiFilesTask.processFiles(MultiFilesTask.java:86)
at com.android.ant.AidlExecTask.execute(AidlExecTask.java:193)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
Here is the build.xml which comes with Android SDK
<mergemanifest
appManifest="${manifest.abs.file}"
outManifest="${out.manifest.abs.file}"
enabled="${manifestmerger.enabled}">
645 <library refid="project.library.manifest.file.path" />
</mergemanifest>
<do-only-if-manifest-hasCode
649 elseText="hasCode = false. Skipping
aidl/renderscript/R.java">
Any idea how I can resolve this issues?
Thanks. Note by using the same machine environment, I was able to build
project from
https://code.google.com/p/android-custom-class-loading-sample/, but not my
own project.
No comments:
Post a Comment