Access graphics from drawable folder of a dynamic feature module from main module

Images
Related searches

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'

Traditionally you cannot access resources from another module, just assets (which are stored raw). Now apparently you can, but it's messy. The whole point of the split API arrangement, however, is that you could indeed access code and resources of all parts (modules) like they where one. I found this is true for the assets folder, as you don't need to dynamically create a new context for the dynamic module reference. I found if you happen to have the same titled asset in your main and dynamic instant module assets folders, it is pulled from the dynamic module.

However, I've still not been able to pull from the dynamic module resources (R), but I'll offer a workaround in answer to my own question until I find an example or get a better answer. You can put your image files in the assets folder of your dynamic module instead, and then pull and convert them as follows:

loadTextureResource("testimage.png");//include file type (.png)

Bitmap bitmap;
public void loadTextureResource(String imagename){

    ImageView mImage=new ImageView(context);
    InputStream ims;

    try {
        // get input stream
        ims = context.getAssets().open(imagename);
        // load image as Drawable
        Drawable d = Drawable.createFromStream(ims, null);
        // set image to ImageView
        mImage.setImageDrawable(d);

        bitmap = ((BitmapDrawable)mImage.getDrawable()).getBitmap();
        ***

Overview of Play Feature Delivery, Images & graphics Use feature modules for custom delivery; Modularize your app A unique benefit of feature modules is the ability to customize how and when feature module in the MyAppProject/features/ directory and specified If you want to access a resource stored in a feature module using a� 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.


Dynamic Feature Modules and accessing resources : androiddev, feature1 - Dynamic feature module (on-demand) getString(R.string.app_string) // Able to access strings in its own module https://i.redd.it/g4z3tb95xxk51.jpg Source code is the Java and Kotlin files in the src folder. AAPT2 supports the compilation of all Android resource types, such as drawables and XML files. When you navigate to one of these destinations, the Dynamic Navigator library first checks if the feature module is installed. If the feature module is already present, your app navigates to the destination as expected. If the module isn't present, your app shows an intermediate progress fragment destination as it installs the module.


A com.android.application module is not meant to access com.android.dynamic-feature module's resources as the dynamic-feature module's resource table is not accessible to the application.

Navigation and Dynamic Features, When you use standard library modules, the main module can see them all. Create a library module with interfaces for dynamic features that acts as a Navigation graph: An XML resource file that contains definitions for all This will add the snapshot repository to access the Dynamic Navigator library. Bitmap File A bitmap graphic file (.png, .jpg, or .gif). Creates a BitmapDrawable. Nine-Patch File A PNG file with stretchable regions to allow image resizing based on content (.9.png). Creates a NinePatchDrawable. Layer List A Drawable that manages an array of other Drawables.


Patterns for accessing code from Dynamic Feature Modules, We're going to call them dynamic feature modules, or DFMs. main source set, but each approach for accessing code dynamically You can also integrate with Dagger 2 to help instantiate the object graph on the DFM side. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.


dynamic feature resource not found exception � Issue #39 , To fix this, move your dynamic module layout files to your main app layout file. Then, in your dynamic module fragment/activity, access the R.layout from your getDrawable(id) val colorRes = splitCompatInstalledContext. Dynamic code loading sample, which demonstrates three different approaches to safely access code from an installed feature module. Codelabs Your First Android App Bundle , a codelab that explores the basic principles of Android App Bundles and shows you how to quickly get started with building your own using Android Studio.


PlayCore API sample, which demonstrates usage of the PlayCore API to request and download on-demand features. Dynamic code loading sample, which demonstrates three different approaches to safely access code from an installed feature module. Codelabs. On demand modules, which helps you create an app that downloads and installs features on demand.