2

I want to load Class in Android (using dexClassLoader) compiled with external libs in my case JadeAndroid.jar. This class (dex) is exported (I'am using ant script) in jar which contains also all JadeAndroid classes. My class extends jade class Behaviour. When I load this class i have an exception:

09-03 21:53:05.319: W/dalvikvm(23201): Class resolved by unexpected DEX:Lcom/example/dex/lib/LibraryProvider;(0x40d80838):0x411aa8 ref[Ljade/core/behaviours/Behaviour;] Ljade/core/behaviours/Behaviour;(0x40d81d18):0x419158
09-03 21:53:05.319: W/dalvikvm(23201): (Lcom/example/dex/lib/LibraryProvider; had used a different Ljade/core/behaviours/Behaviour; during pre-verification)
09-03 21:53:05.319: W/dalvikvm(23201): Unable to resolve superclass of Lcom/example/dex/lib/LibraryProvider; (337)
09-03 21:53:05.319: W/dalvikvm(23201): Link of class 'Lcom/example/dex/lib/LibraryProvider;' failed
09-03 21:53:05.319: W/System.err(23201): ***  Uncaught Exception for agent buyer1  ***
09-03 21:53:05.319: W/System.err(23201): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
09-03 21:53:05.319: W/System.err(23201):    at dalvik.system.DexFile.defineClass(Native Method)
09-03 21:53:05.329: W/System.err(23201):    at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:195)
09-03 21:53:05.329: W/System.err(23201):    at dalvik.system.DexPathList.findClass(DexPathList.java:315)
09-03 21:53:05.329: W/System.err(23201):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:58)
09-03 21:53:05.329: W/System.err(23201):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-03 21:53:05.329: W/System.err(23201):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-03 21:53:05.329: W/System.err(23201):    at pl.edu.kosttek.jadebook.agent.AgentBuyerLoader$GetJarBehaviour.getBehaviour(AgentBuyerLoader.java:227)
09-03 21:53:05.329: W/System.err(23201):    at pl.edu.kosttek.jadebook.agent.AgentBuyerLoader$GetJarBehaviour.action(AgentBuyerLoader.java:166)
09-03 21:53:05.329: W/System.err(23201):    at jade.core.behaviours.Behaviour.actionWrapper(Behaviour.java:344)
09-03 21:53:05.329: W/System.err(23201):    at jade.core.Agent$ActiveLifeCycle.execute(Agent.java:1532)
09-03 21:53:05.329: W/System.err(23201):    at jade.core.Agent.run(Agent.java:1471)
09-03 21:53:05.329: W/System.err(23201):    at java.lang.Thread.run(Thread.java:864)

How I compile my class to jar:

  1. put JadeAndroid.jarto libs folder

  2. use ant script which creates dex and puts it into jar

It is possible to exclude this AndroidJade classes ?

1
  • Maybe this isn't the solution to your problem, but make sure that the parent classloader you supply to DexClassLoader() comes from context.getClassLoader() and not from ClassLoader.getSystemClassLoader(). I wasted an hour on that stupidity. Commented Jul 9, 2013 at 17:00

1 Answer 1

1

I think that the problem is that you have Jade classes in Jar, and the same Jade files already in your Classloader, which is misleading for JVM.

Maybe you can try to compile JAR, but not compile-in Jade classes to it? So just include it for compilation, but in the way they will not appear in JAR? In such case you will have no problems when loading the class and the goal will be achieved.

Upd: If you are compiling Jar in Android-way, so I will suggest to link Jade for compilation, but not put it into libs/ folder. It will prevent it to be compiled-into the jar.

Good luck

Sign up to request clarification or add additional context in comments.

2 Comments

I Think that is solution to include jade in compilation but exclude it from jar. But question is how to do it I have no experience with ant
I think you should check this: stackoverflow.com/questions/5106749/… Note - the goal is just to add Jar to classpath, and exclude it from /libs/ folder. But the accepted answer of that thread can help, I hope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.