2

I am getting Resources$NotFoundException in my dynamic feature module while accessing the layout file. Full error logs below. How can I fix this?

android.content.res.Resources$NotFoundException: Resource ID
#0x7e070001
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:239)
        at android.content.res.MiuiResourcesImpl.getValue(MiuiResourcesImpl.java:96)
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2317)
        at android.content.res.Resources.getLayout(Resources.java:1191)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at android.view.View.inflate(View.java:26090)
        at com.x.y.player.ContentPlayer.<init>(ContentPlayer.kt:144)

CODE FILE

init {
        val view = FrameLayout.inflate(context, R.layout.content_player_layout, this)
        videoTextureView = view.findViewById(R.id.videoTextureView)
        videoSurfaceView = view.findViewById(R.id.videoSurfaceView)
}

Error on line val view = FrameLayout.inflate(context, R.layout.content_player_layout, this)

Ankush Kapoor
  • 445
  • 1
  • 8
  • 20
  • Have you tried to manually keep resource from shrinking? https://stackoverflow.com/questions/43838269/android-how-to-tell-shrinkresources-to-keep-certain-resources – Dmytro Rostopira Jul 12 '21 at 09:31
  • @DimaRostopira minifyEnabled is false. Also I am able to see the layout file in aab – Ankush Kapoor Jul 12 '21 at 09:35
  • minify is for code shrinker, resource shrinker is disabled using `shrinkResources false`. Try to copy your layout resource to dynamic feature module if it's currenly only in `app` module – Dmytro Rostopira Jul 12 '21 at 09:41
  • @DimaRostopira shrinkResources is also false and layout files are present in the dynamic feature module only. – Ankush Kapoor Jul 12 '21 at 09:59
  • Does this answer your question? [Android dynamic feature module, resource not found](https://stackoverflow.com/questions/54537418/android-dynamic-feature-module-resource-not-found) – Dmytro Rostopira Jul 12 '21 at 10:06

1 Answers1

0

Make sure you are importing the correct package resources. If your inflated layout is in main module, then import main module package resource(R), if it is in dynamic feature module, then import module package resource(R) in your inflated layout class.

Suppose your app main package is "app.main.package" and dynamic feature module package is "app.dynamic.package". Import them accordingly to use the correct resource.

if layout in main=> import app.main.package.R;

if layout in dynamic feature module=> import app.dynamic.package.R;