I want to load some classes from an APK into an already running Service at runtime, but I get the following error:
11-03 16:51:13.570 20227-20240/com.somecompany.android.core W/dalvikvm﹕ Class resolved by unexpected DEX: Lcom/somecompany/android/core/db/DatabaseManager;(0x2ce11280):0x392d6000 ref [Lcom/somecompany/android/core/CoreModule;] Lcom/somecompany/android/core/CoreModule;(0x2cdb1d20):0x38f40000
11-03 16:51:13.570 20227-20240/com.somecompany.android.core W/dalvikvm﹕ (Lcom/somecompany/android/core/db/DatabaseManager; had used a different Lcom/somecompany/android/core/CoreModule; during pre-verification)
11-03 16:51:13.570 20227-20240/com.somecompany.android.core W/dalvikvm﹕ Unable to resolve superclass of Lcom/somecompany/android/core/db/DatabaseManager; (720)
11-03 16:51:13.570 20227-20240/com.somecompany.android.core W/dalvikvm﹕ Link of class 'Lcom/somecompany/android/core/db/DatabaseManager;' failed
11-03 16:51:13.570 20227-20240/com.somecompany.android.core W/dalvikvm﹕ threadid=11: thread exiting with uncaught exception (group=0x2c7dbfc0)
11-03 16:51:13.570 20227-20240/com.somecompany.android.core E/com.somecompany.android.core.CoreApplication﹕ Thread com.somecompany.android.core.CoreService-80000000 has crashed
11-03 16:51:13.570 20227-20240/com.somecompany.android.core E/com.somecompany.android.core.CoreApplication﹕ java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at dalvik.system.DexFile.defineClass(Native Method)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:211)
at dalvik.system.DexPathList.findClass(DexPathList.java:315)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:58)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at com.somecompany.android.core.CoreModuleLoader.loadRegisterModules(CoreModuleLoader.java:56)
at com.somecompany.android.core.CoreModuleLoader.load(CoreModuldeLoader.java:110)
at com.somecompany.android.core.CoreService$1.run(CoreService.java:148)
at java.lang.Thread.run(Thread.java:856)
I think the problem is that the APK generated by Android automatic build packs all the Service classes into the APK, which at time of loading causes problems because these same classes already exist into the Service. The Service is linked as a JAR at compile time.
How can I modify the build process so the Service JAR is NOT included in resulting APK? Thanks in advance.
EDIT: classes.dex
inside the APK does have the Service classes.
EDIT: this is the build.xml
node used to DEX the JARs. Unfortunately I have no idea about ANT on how to configure this part, any help appreciated.
<!-- Configurable macro, which allows to pass as parameters output directory,
output dex filename and external libraries to dex (optional) -->
<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>
<dex executable="${dx}"
output="${intermediate.dex.file}"
dexedlibs="${out.dexed.absolute.dir}"
nolocals="@{nolocals}"
forceJumbo="${dex.force.jumbo}"
disableDexMerger="${dex.disable.merger}"
verbose="${verbose}">
<path path="${out.dex.input.absolute.dir}"/>
<path refid="out.dex.jar.input.ref" />
<external-libs />
</dex>
</sequential>
</macrodef>