lundi 16 janvier 2017

Visibility issue for classes loaded by dex loader

I have two Android applications A and B. I want to generate a DEX of app B and load it dynamically during runtime into app A via a DexClassLoader. In application B I have mainly two classes that are important to be used by app A.

However, I have problems with the visibility of the needed classes in the first application.

This can be illustrated by the following:

final DexClassLoader dexClassLoader = new DexClassLoader(file.getAbsolutePath(), optDexDir.getAbsolutePath(), libsPath, ClassLoader.getSystemClassLoader());

Class<?> classToLoad = dexClassLoader.loadClass(completeClassNameOfA);
final Object instance = classToLoad.newInstance();

Method methodToLoad = classToLoad.getMethod(methodNameOfClassA, ClassLoader.class);
methodToLoad.invoke(instance, context.getClassLoader());

In the method I am invoking in app B, I try to find the class in the given class loader of A that I pass via a parameter like:

appAClassLoader.loadClass(AppBSecondClass.class.getName());

which obviously results in a NoClassDefFound exception.

Is there any way to make the class visible in the class loader of app A?

Thanks in advance





Aucun commentaire:

Enregistrer un commentaire