vendredi 28 avril 2017

Java reflection handling library changes

Ok so I have an Android app and I started creating an addon system for the app so developers can code content providers that the app can then use to generate different content, I will not go through the whole procedure but everything works fine like so:

1) I created a library called com.myaddonlib that I imported in my project in this library there is an interface and different objects.

2) Now a developer can create a simple Java project on his end, import the library com.myaddonlib, and implement the interface on his main class which have methods that return different objects from the library.

3) Back on the android app, I can load the .jar file created by the developer (after the classes.dex is added to the jar file) and with the android DexClassLoader I can load the implemented interface like so :

DexClassLoader classloader = new DexClassLoader(jarFilePath, tempDirectory, null, context.getClass().getClassLoader());     
Class classToLoad = classloader.loadClass("com.apackage.Addon");

where Addon is the class created by the addon developer that implements the interface from the library residing in a package named com.apackage. I can then cast the interface from the library com.myaddonlib to a new instance of classToLoad and call the functions that the addon developer implemented.

Now here is the issue lets say I decided to update the addon library and remove one of the variables, meaning that the addons object is now different from the object in the updated library. Even when the changed variable is not used something causes the app to crash without any error. Just the fact that both objects are different causes something to malfunction. Now this is not an easy procedure to explain so I would understand that given my bad english some have trouble following. My issue is that I need to know how to avoid this crash due to the change of the library on one of both ends.





Aucun commentaire:

Enregistrer un commentaire