Earlier quoted context omitted.
We are now in a “dependency-oriented programming environment” (D.O.P.E) world. One the one hand, it’s easy to sniff at the use of dependencies, when we have these kinds of disasters, but on the other hand, dependencies give us the ability to do truly great stuff. For example, I program Apple devices (not just iOS). I wrote my first Apple code in 1986, so I have some “prior art.” I’ve “seen it all.” I remember the day…
For Java you can actually control a lot of this through a security manager: https://stackoverflow.com/questions/5401281/preventing-syste... And I think you can even control the loading through a custom class loader. It's a bit of work but it should give you decent oversight over the dependencies you really don't trust but have to use.
A side note: on Android, class loaders are definitely of no use for this purpose. Android runtime uses its custom bytecode language and file format that packs the entire classpath of your app into one .dex file. You can't load separate classes from these, only the entire thing all at once.
(yes there's multidex for large apps but the way classes are split between files is rather random in my experience)