0

I have made some modules to each features of my app, then I choose them in my gradle conf file. However, the modules are injected at the compile build time but I want to load them at the runtime. If they are loaded at runtime, the user could load the features he wants only.

I already use reflection to load modules in my main application module, so I just need to modify the gradle buid file.

Is it possible to dynamically load aar lib or apk with dex loader ?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Note that an AAR and an APK have things other than DEX code that the code might be using, such as resources. Also, bear in mind that what you are proposing violates the current Play Store distribution rules, so I hope that you were planning on distributing your app by some other means. Also, please take care to ensure that you only load DEX modules from sources with expected signatures, so that your app does not become a vehicle for code-injection attacks. – CommonsWare Nov 21 '17 at 13:32
  • You want to decrease APK size? – nhoxbypass Nov 21 '17 at 13:45
  • Right, but as said, I need to put the modules on the Store so they have to respect the distribution rules... – Antoine Gicquel Nov 21 '17 at 13:58
  • "I need to put the modules on the Store so they have to respect the distribution rules" -- if you are referring to the Play Store, note that the ban is on dynamically loading code, not how that code is distributed. You are welcome to distribute plugins on the Play Store as apps, but you have to integrate with them via IPC mechanisms (`startActivity()`, `startService()`, `sendBroadcast()`, etc.). – CommonsWare Nov 21 '17 at 14:36
  • Yes I did. Okay, thanks for your answer ! – Antoine Gicquel Nov 21 '17 at 14:57

1 Answers1

0

Yes you can use DexClassLoader and Java Reflection (Class<Object>.getMethod(...).invoke()). But it will slow down your app and make developers hard to implement and fix bugs.

If you really want to do this to decrease your APK size see detailed answer here.

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
  • The APK size doesn't really matter. My issue is : the app contains all the features but I want a leigtweight app and let the user choose their modules. I also want to put these modules on the Play Store. I know Android that's not really the android way to archieve this, but I really need to implement a Plugin Architecture. – Antoine Gicquel Nov 21 '17 at 13:56