5

I am trying to use the DexClassLoader to download a JAR/APK in my app. I would like to modularize my app so I can download UI flows the user might go on demand instead of shipping them all together into my main app.

Loading the actual classes works fine and I managed to load some UI components which I can add to my host activity.

My problem is that obviously I cannot access or add resources (Strings, drawables, layouts) to my downloaded package because they do not come with my host APK. Is it possible to dynamically load resources for my downloadable JAR/APK?

dnkoutso
  • 6,041
  • 4
  • 37
  • 58

1 Answers1

1

You can "dynamically" download any resources you want, put them in a directory you choose, and use them in your app. It's what I currently do in an app. I don't think you can put them in the same directory with the resources that are in your project, but does that matter?

Christine
  • 5,617
  • 4
  • 38
  • 61
  • But how? In the downloaded code if I do anywhere R.string.my_string the R file of the host app does not include my_string. In fact it will become a constant and might point to a much different string. I know because I've actually tried it and the string that came out was completely different. The same with applies for layout resources. I am also missing Androids dynamic layout selection per the device configuration. – dnkoutso Sep 24 '12 at 21:25
  • No, you can't easily include your own assets in the R file. But if you download the assets, you don't have to. You download your string and png files to Environment.getExternalStorageDirectory()+"/assetsDir", then you read them from there. You can't include stuff in the R file because the R file is built at compile time, not at run time. – Christine Sep 25 '12 at 14:39
  • I understand and I agree. So the only way around this is to extract them and use them from the /assetsDir? I will have to write my own resource loading then, which is what I am trying to avoid as I might lose the dynamic resource loading for different screens and configurations. Any other ideas? – dnkoutso Sep 25 '12 at 15:25
  • You can create different assetDirs for different screen resolutions/dimensions/etc, and put the name of that dir in the appropriate /res/values/strings.xml file. The drawback of all this is that you load all resources to the phone, rather than just the ones for that type of phone. – Christine Sep 28 '12 at 16:21