3

so I have a couple of features that share common code - let's call them "feature1" and "feature2". I can't add the shared code as dependencies for "feature1" and "feature2" - Android studio throws the following error:

Multiple APKs packaging the same library can cause runtime errors. Adding the above library as a dependency of the base module will resolve this issue by packaging the library with the base APK instead.

So I thought I just create another dynamic feature module - let's call it "core" - to deliver the shared dependencies there. Which also works, kind of. I can access all the java classes from "core" inside "feature1" and "feature2", but as soon as I want to access a resource I get an ResourceNotFoundException. The features are deliver Fragments that call SplitCompat.install(context) in their onAttach() function.

So my question is - is it even possible to have a dynamic feature module where common code is stored, or should this all go in the app?

Thanks & Regards, Romanski

Shreeya Chhatrala
  • 1,441
  • 18
  • 33
Romanski
  • 730
  • 8
  • 27
  • Ideally, if there are 2 or more feature modules using the same code, it would be good to have them as part of the base app unless these are heavy resources and are not so critical to the application. – Dinesh Oct 15 '19 at 12:57
  • They are very heavy and optional - that's why I wanted to load them in an additional feature – Romanski Oct 15 '19 at 14:38
  • I'm not sure that multi level modules is supported at the moment. I would suggest to either put the common code in the app, or merge the two features together. – Pierre Oct 15 '19 at 18:22
  • Can you help me with this? Detailed Question: https://stackoverflow.com/questions/64191100/using-dynamic-feature-module-fonts-downloaded-and-installed-in-asset-folder-but – jazzbpn Oct 04 '20 at 13:46

1 Answers1

5

Now support for feature on feature dependencies have been introduced in the latest release of gradle:

https://developer.android.com/studio/releases/gradle-plugin#feature-on-feature

shubhamgarg1
  • 1,619
  • 1
  • 15
  • 20