1 year ago
#372949
francogrex
class loaded via dalvik.system.PathClassLoader cannot resolve dependencies on classes in the app
I am loading a class using dalvik.system.PathClassLoader and by reflection creating newInstance from the constructor. This works fine if the loaded class contains only the "standard" java and android libs but not when it imports "custom" libs, even though those custom libs are supposed to be in the "classpath". See the decompiled apk below, the MainActivity is in com and the imported custom lib is in kawa... (for example import kawa.lib.ports) however I get the message cannot resolve (for example kawa...). Are those classes not in the actual classpath of the MainActivity in com? Note I have no problems during compilation of the class that I load because at compilation time (done externally) I explicitly put the needed custom libs in the classpath. The problem is occurring at runtime. Thanks.
I should add that if I use a terminal emulator, and run the program on the command line instead of the app such as: dalvikvm -cp .:myapp.jar ... and do the same as before (i.e. load the external class and invoke the class method on the instance, then there is not problem with unresolved lib dependencies, because I suppose the "-cp" puts everything on the same needed classpath. Hence the questions become: What is actually the android app's classpath? and can it be dynamically and painlessly extended to encompass several? libs/locations?
Update 05/04/2022: I am happy to report that I fixed the problem and I did it by using the context's getClassLoader (e.g. context.getClassLoader) instead of the getSystemClassloader (which was published as the way to dynamically load dex classes using dalvik.system.PathClassLoader. Although nobody offered any answers, I keep this it can help others who find themselves searching for similar answers.
android
classloader
dalvik
dexclassloader
0 Answers
Your Answer