The context:
I use AdMob mediation to display banner ads in my app. I integrated Millennial ad network SDK and Millennial AdMob adapter.
Problem: my app supports Android API 9+, whereas Millennial SDK supports API 16+. Worse, instead of gracefully failing (returning no ad to the AdMob mediation layer so that it can continue going down the mediation waterfall), the SDK crashes on devices running Android < 16 (Fatal Exception: java.lang.NoSuchMethodError
android.webkit.WebSettings.setAllowUniversalAccessFromFileURLs
)
Apparently Millennial developers are not planning to fix this, they recommend publishing 2 distinct APKs ("<16" without their SDK and "16+" with their SDK), which is a troublesome solution.
I would prefer a simpler solution: on devices running Android API < 16, I'd like to reproduce what happens when an AdMob adapter is missing: AdMob mediation just goes to the next network. This would mean unloading or erasing the Millennial adapter class before I instantiate the AdMod mediation banner.
The question:
Is there any way to prevent any future instantation of a given class (from a 3rd party library) at runtime? (e.g. by forcing a ClassNotFound exception)