I'm getting my feet wet with dynamic module split API delivery in order to break up my game app into Instant and Installable versions. I've been following the Codelabs tutorial here https://codelabs.developers.google.com/codelabs/on-demand-dynamic-delivery/index.html#0. Unfortunately it uses Kotlin for the MainActivity code, which is less specific than Java, but still fairly followable if you've done a Kotlin tutorial. The example includes accessing a text tile in an 'assets' folder in an 'assets' feature module with the following:
private const val packageName = "com.google.android.samples.dynamicfeatures.ondemand"
val assetManager = createPackageContext(packageName, 0).assets
// Now treat it like any other asset file.
val assets = assetManager.open("assets.txt")
val assetContent = assets.bufferedReader()
.use {
it.readText()
}
For now I just want to access graphic files in a drawable folder of my dynamic feature module. I'll only be using my dynamic feature module to store large graphics that would take me over the 10 MG limit for an Instant app download. What would be the cleanest way to do this?
Main 'app' module:
Java code in 'app':
loadTexture(R.drawable.aaa_image);
Bitmap bitmap;
public void loadTexture(final int resourceId){
bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
***
Dynamically delivered 'installationassets' module:
Still java code in 'app', won't reach:
loadTexture(R.drawable.testgraphic);
cannot resolve symbol 'testgraphic'
If your dynamic feature modules include activities or services which interact with system components, such as launcher shortcut icons, dynamic shortcuts, or notifications, you may have a hard time customising your app to support these. This is because these system components are unable to access resources like icons from dynamic modules.
We’re going to call them dynamic feature modules, or DFMs. When you distribute your app as an Android App Bundle, Play Store will deliver these modules to user’s devices as separate APKs at the appropriate time.
A Feature Module in Angular is a module other than our main application root module that is decorated by @ngModule () decorator and hence share the same property configurations like application root module.
The storage module is a dynamic feature module configured for on-demand delivery. What we’ll be looking at in this article is how you can access a class that lives in the storage module from the base app module.
I found a working solution to load drawables from a feature module resources. The trick is to use the correct package name for the module.
Example:
build.gradle
dynamicFeatures = [":FeatureModule"]
Java
int drawableResId = context.getResources().getIdentifier("your_drawable_name", "drawable", "com.project.FeatureModule");
context.getDrawable(drawableResId);
Reference article
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With