Last active
February 4, 2018 19:39
-
-
Save davethomas11/58c749613b5b048c9432de767d3bae04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModuleLoader(val cacheDir: String) { | |
fun load(dex: File, cls: String = "com.example.dynamicmodule.DynamicModule"): IDynamicModule { | |
try { | |
val classLoader = DexClassLoader(dex.absolutePath, cacheDir, | |
null, this.javaClass.classLoader) | |
val moduleClass = classLoader.loadClass(cls) | |
if (IDynamicModule::class.java.isAssignableFrom(moduleClass)) { | |
return moduleClass.newInstance() as IDynamicModule | |
} | |
} catch (e: Exception) { | |
Log.e("ModuleLoader", e.message, e) | |
} | |
return IDynamicModule { "Failed to load" } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment