I'm working on an Android application with pluggable .jar modules.
My problem is, when I load two different .jar files, the classes from the first .jar file cannot "see" (Class.forName()) classes from the second .jar file and vice-versa. I load external .jars from the main application with DexClassLoader.
=== Here is an example situation ===
We have two modules:
- First.jar (with classes FirstA and FirstB, packaged in classes.dex)
- Second.jar (with class SecondA, again in classes.dex)
By using DexClassLoader I load First.jar. Everthing is OK. Then again by using DexClassLoader I load Second.jar and SecondA cannot "see" FirstA or FirstB with Class.forName(). I get java.lang.ClassNotFoundException. When I check for FirstA from SecondA with Class.forName() I'm not setting the classloader parameter.
=== End of example situation ===
I was thinking that when a class is loaded into the dalvik/jvm, it will be visible/accessible from all other classes in that same dalvik/jvm. This is not the case or I'm totally wrong? What I have to do in order to make SecondA to see classes from First.jar (Class.forName())?
Any suggestions or resources I can learn from are welcome! I'm stuck guys!
EDIT:
- All modules are loaded runtime.
- Every module is loaded by different instance of DexClassLoader because I'm required to provide path to the .jar file and I cannot pack all modules in one jar.