Native code sometimes requires additional resources, such as layout or image files. These work in slightly different ways on Android and iOS but can be easily included in modules for both.
To include resources they must be placed in the
folder. Once there the Android inspector project should be updated: in Eclipse, you'll see a resources in the ForgeInspector project's
res folder, and
R.java will have been generated in the ForgeModule's
For more information about what kind of resources can be added to your module and how they can be used with the Android SDK, see the `official Android docs concerning App Resources.
Important: Due to a limitation of ADT, in platform versions less than
v2.0.2it is necessary to move
R.javafrom the ForgeModule's
trigger-genfolder into the
srcfolder, alongside your
To do this, you can use Eclipse's Move... refactor to change the package the class is in.
This is only necessary for platform versions older than
v2.0.2. You'll need to do this refactor each time you regenerate your inspector project.
In your code, you can refer to your resources via the
R class as normal, e.g.:
LayoutInflater inflater = (LayoutInflater) ForgeApp.getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.myLayout, null);
On iOS, any resources included in your module must be part of a bundle.
3rd party bundles can be included by placing the bundles in
module/ios/bundles. An inspector project update will then be
required to include them in the inspector for development
If you have resources such as images that you want to include in your
module, you must create your own bundle. The inspector project includes
ForgeModuleResources target which can be used to help with this:
Product Namefor the ForgeModuleResources target.
Add the required resources to the
ForgeModule project and include
them in the
Use the named bundle to reference these resources from your native code, with code like this:
NSString * bundlePath = [[NSBundle mainBundle] pathForResource:@"my_bundle_name" ofType:@"bundle"]; NSBundle * myBundle = [NSBundle bundleWithPath:bundlePath];
For more information, see Accessing a Bundle's Contents.
UniversalForgeModuleyour bundle will be output in the build folder: make sure to include this in
ios/bundles/in your module folder.
Run UniversalForgeModule to produce build folders.
Update iOS inspector.
Reopen Xcode. Note that
<bundle_name>.bundle is listed under ForgeInspector's frameworks.
Any new or changed resources will require you to start again at step 1.