androidandroid-app-bundledynamic-feature-module

Android dynamic feature modules dependencies


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


Solution

  • Now support for feature on feature dependencies have been introduced in the 4.0 release of AGP:

    https://developer.android.com/build/releases/past-releases/agp-4-0-0-release-notes#feature-on-feature