I am trying to add the new Android dynamic delivery feature to my app, but my attempts to access the resources of the dynamic feature module keep failing.
The basic idea is to load a module with no code but a bunch of vector files as drawable resources.
I am able to load the module and even access the assets of given module, but I can't figure out how to access the resources.
val res = context.createPackageContext(context.packageName, 0).also {
SplitCompat.install(it)
}.resources
val assetsStream = res.assets.open("test.txt")
val assetContent = assetsStream.bufferedReader()
.use {
it.readText()
}
var iconResourceId = res.getIdentifier(stringIdentifier, IDENTIFIER_DRAWABLE, context.packageName)
As I said, I am able to read the text in the assets txt file, but I don't seem to find any drawables in the resources.
When i try to get drawables which i know are in the resources folder of the dynamic module i get a ResourcesNotFoundException
I've read through the Android Docs that are provided by Google but i'm not able to find detailed information about how to access a downloaded modules recources
https://developer.android.com/guide/app-bundle/playcore#access_installed_modules
I was able to solve this by replacing the
packageName
for the feature-module package name, on the method ofres.getIdentifier(..., packageName)
App package name:
com.example.my_app_package
Feature's resources package name:
com.example.my_app_package.my_dynamic_feature
I'm not sure exactly from where the value
my_dynamic_feature
is obtained, but the full package will not be the one that you defined on the module's build.gradleapplicationId
or AndroidManifestpackage
property.