1

Around 2 days ago, i found out about the DexClassLoader Library by Android. As a rather mediocre programmer i have a few questions regarding this library/class/tool. The questions i have mainly focus on this Documentation:

  1. It states, that it loads a external .jar or .apk file. Now lets assume i have my Project as follow:

    com.me  
    -->src    
    ---->main    
    ---->fragment1    
    ---->fragment2
    -->layout    
    ---->layout_main    
    ---->layout_fragment1
    ---->layout_fragment2
    

    How exactly would i now extract fragment1 with its corresponding layout into an .jar or .apk file, that my DexClassLoader can implement this file. And more importantly how do i transform these into such a file.

  2. How do i implement all the functions i do have in my module (the exported Fragment)? I am guessing it is via an Interface, but i am neither sure, nor have found a good example online, as it kind of seems, as if it is a kind of underused feature.

  3. Quiet similar to point 2, but how do i display this Fragment. If it is solved via an Interface, then i dont really have a way to call getFragmentManager().beginTransaction().add(R.id.smthng,Fragment1).commit();

Thanks for any sort of answer regarding any of these questions :) If i have more questions i will update this post. Cheers

Jacobus

PlatinTato
  • 378
  • 2
  • 19
  • First of all you will be **not able** to load resources from some kind of external library ... if you wana put fragment into dynamicaly loaded dex then you should build UI there from the code ... – Selvin Dec 11 '15 at 12:08
  • @Selvin thanks :D thats already a valuable information – PlatinTato Dec 11 '15 at 12:09
  • and here is my example : https://gist.github.com/SelvinPL/eefa88add4fa33f41ca8 ... the dynamicfragment and dynamicfragment2 are just library modules ... and dynamicfragment.jar and dynamicfragment2.jar contains only classes.dex from output of those libraries – Selvin Dec 11 '15 at 12:10
  • @Selvin thank you :D. what exactly do i have to do, to put such a fragment into a .apk? – PlatinTato Dec 11 '15 at 12:14
  • there should be single classes.dex in zip (apk, jar, whatever) ... to get classes.dex folow [this](http://stackoverflow.com/questions/8348144/how-to-convert-jar-or-class-to-dex-file) to get classes.jar you can find here *PROJECT_PATH\YOUR_LIBRARY_MODULE **\build\outputs\aar** \YOUR_LIBRARY_MODULE_BULILD_TYPE **.aar\classes.jar*** – Selvin Dec 11 '15 at 12:21
  • @Selvin i am slowly but surely grasping your code :D thank you sir – PlatinTato Dec 11 '15 at 13:27
  • http://selvin.pl/MyApplication1.zip <= full project ... the main problem is to automate createing jars with classes.dex ... but for tests tou can use command line dx – Selvin Dec 11 '15 at 13:33
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97645/discussion-between-jacobus-conradi-and-selvin). – PlatinTato Dec 11 '15 at 13:39
  • @Selvin i would love it if you would be accesible for a disscusion :D – PlatinTato Dec 11 '15 at 13:51
  • so you have a `Fragment` in some external `.apk` file and you want to call `FragmentTransaction#add` in your app? or something else? – pskink Dec 11 '15 at 15:37
  • @pskink basically yes – PlatinTato Dec 11 '15 at 16:26
  • then you could try [this](https://github.com/singwhatiwanna/dynamic-load-apk/blob/master/README-en.md) – pskink Dec 12 '15 at 09:11
  • @pskink thanks :) ill take a look – PlatinTato Dec 13 '15 at 14:15
  • and if you want minimalistic working example see `resource managment` section in the link i posted to find out how you can use resources from your external apk – pskink Dec 13 '15 at 14:25

0 Answers0