I have an Android application that requires the ability to load external Jar files. I know the locations of the Jars.
I have been playing with the PathClassLoader class provided by the Android API to no avail. I am using the following code from within an Activity:
String jarPath = "/sdcard/jars/testjar.jar";
PathClassLoader myClassLoader = new PathClassLoader(jarPath, ClassLoader.getSystemClassLoader());
try
{
Class<?> clazz = Class.forName("com.test.Class1", true, myClassLoader);
}
catch(Exception ex)
{
ex.printStackTrace();
}
Upon instantiating the PathClassLoader instance, Dalvik prints a message to LogCat telling me that it could not find the 'classes.dex' file. After that, 'Class.forName' throws a 'ClassNotFoundException'.
I'm trying to find a way to be able to load classes from the external Jar file without the need for the 'classes.dex' file. The Jar file does not contain this file, but when other applications are built with the Jar in the classpath, Dalvik can load the classes quite happily.
Simply put: How can one load classes from an external Jar file without the need for 'classes.dex'?
Many thanks, P
Update The message logged by Dalvik is
Zip is good, but no classes.dex inside, and no valid .odex file in the same directory