1

I'm attempting to retrieve a list of classes in a given package name on Android. I have a working method which looks like this:

fun getClasses(context: Context, packageName: String): List<Class<*>> {
    val dexFile = DexFile(context.applicationInfo.sourceDir)
    return dexFile.entries().asSequence()
        .filter { it.startsWith(packageName) }
        .map { context.classLoader.loadClass(it) }.toList()
}

The issue with this implementation is that is uses the deprecated DexFile class. I've attempted to use several of the implementations found in the answers of this question however I was unable to get any of them to return any classes.

Is it possible to retrieve a list of classes in a given package on Android without using the DexFile class?

jos76
  • 141
  • 1
  • 2
  • 8

0 Answers0