Android dexclassloader get a list of all classes

I use an external jar of assets or sdcard in an Android application. For this I use DexClassLoader.

DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader()); 

to load the class:

 Class myNewClass = cl.loadClass("com.example.dex.lib.LibraryProvider"); 

It works very well, but now I want to get a list of all the class names in my DexClassLoader. I found this one to work in java, but in Android there is no such thing.

The question is, how can I get a list of all class names from DexClassLoader

+6
source share
1 answer

To list all the classes in the .jar file containing the classes.dex file, you use DexFile , not DexClassLoader , for example. eg:

 String path = "/path/to/your/library.jar" try { DexFile dx = DexFile.loadDex(path, File.createTempFile("opt", "dex", getCacheDir()).getPath(), 0); // Print all classes in the DexFile for(Enumeration<String> classNames = dx.entries(); classNames.hasMoreElements();) { String className = classNames.nextElement(); System.out.println("class: " + className); } } catch (IOException e) { Log.w(TAG, "Error opening " + path, e); } 
+11
source

Source: https://habr.com/ru/post/924164/


All Articles