react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Google Play feature (Dynamic Modules) Support for local resources

Open amank22 opened this issue 3 years ago • 5 comments

Topic:

Play Feature Delivery

Issue:

Resources can not be loaded from feature module. [res/* folder, assets/* will work]

Scenario:

  • Put react native bundle in feature module of Android.
  • Load the module. (Using native code, working fine)
  • React activity is started and all the text is shown. (Taking example of react-native starter project screen)
  • Images are not shown. (Or in-fact any resource which you put it res/ folder)

Anything in assets/ folder will work properly. Network images are also loaded properly.

Reason:

This is because according to Feature Resources Section in Android docs, you can see that any resources in dynamic feature module will have package with feature module name. Like this,

App package name: com.example.my_app_package Feature's resources package name: com.example.my_app_package.my_dynamic_feature

Now at most for the places we get resource from string identifier which takes a package. This context.getPackage() will return application package. This causes the id to be returned as 0. (For a fact, If I change the package with context.getPackage() + ".featureModule" , it is able to find the resource. (This is the file below while debugging)

https://github.com/facebook/react-native/blob/dc80b2dcb52fadec6a573a9dd1824393f8c29fdc/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.java#L63

If we can find some way to actually pass the correct package name which we can append here (maybe from some prop in image) or some better solution, it will be great.

There is method resources.getResourcePackageName(resId) which takes an ID and gives correct package name but this is of no use here.

These are few places I found similar calls: getIdentifier Search on Rn

amank22 avatar May 28 '21 10:05 amank22

Hi, Any help regarding this?

amank22 avatar Feb 17 '22 06:02 amank22

@amank22 Cann you add an example of using Play Feature Delivery with React Native? I can't find a library / documentation to do that.

ChocolateLoverRaj avatar May 06 '22 18:05 ChocolateLoverRaj

@amank22 Cann you add an example of using Play Feature Delivery with React Native? I can't find a library / documentation to do that.

Hi, I currently don't have any sample project. But we did a POC.

Hoping you know how dynamic feature works and you have done the code to load a simple dynamic feature. Following recommendations you can follow:

  • You should put your index bundle file in assets of dynamic feature module.
  • resources will go in main app module (better if you just fetch images from backend/api service for app size savings)
  • You can initiate react host and packages from dynamic module (you can use anything from main module)

What we were trying to achieve was to split react bundle with different hosts but that was also achieved through some hacks (I don't remember as rn part was done by some other dev). Also we never took this live because of business priorities but it is doable.

Hope I can help a little bit and do ask any specific question if you have in mind and I'll try to help.

amank22 avatar May 06 '22 18:05 amank22

@ChocolateLoverRaj These might help you-

https://github.com/varunon9/dynamic-feature-delivery-react-native https://github.com/varunon9/react-native-multiple-bundle

varunon9 avatar May 09 '22 03:05 varunon9

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Feb 03 '24 05:02 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Feb 10 '24 05:02 github-actions[bot]