Search code examples
androidandroid-librarydynamic-feature-module

Third party library of dynamic feature module cannot access resources


I have a application which has a dynamic feature module. In dynamic feature module, there is a form with images, input fields and also it has a buttton which access another third-party library.

Third-party library has a activity and fragment. While opening fragment inside activity, I am receiving below error, although there is container in activity's layout:

No view found for id 0x7f080053 (com.app.sample:id/container) for fragment SampleFragment{eed53f7 (5e4c0693-09a2-4725-a6de-1df49dd818f0) id=0x7f080053}

When accessing drawables in this third-party library, getting below error:

java.lang.NoSuchFieldError: No static field ic_back of type I in class Lcom.third.library/R$drawable; or its superclasses (declaration of 'com.third.library.R$drawable' appears in /data/app/com.app.sample-QtC8XuamC1fHEVU4FUpWaA==/split_thirdparty.apk)

It is fine when I use this library in a application without dynamic feature module. enter image description here


Solution

  • Generally, when SplitCompat.installActivity(this) isn't called in Activity2, this won't work. While not having the source code, you'd have to extract the package and re-package it properly, because the Activity2 (or even the whole library package) likely isn't compatible with DFM.

    After you enable SplitCompat for your base app, you need to enable SplitCompat for each activity that your app downloads in a dynamic feature module.

    Here's another answer of mine, which demonstrates access through reflection.