Tool R Class Generator [Library Development Tool]

What is it?
This is a tool to automatically generate a B4A-type R class (in java) when developing libraries.

This is NOT required for any B4A use code.
This is NOT a requirement for library generation.

This is only required for a particular methodology of library wrapping. It allows you to access resource files from within the library without packaging it yet.

How was it built?
This is a python script turned to an .exe in pyinstaller.

How to run it?
Run this in the folder with the base class of the source you are trying to wrap. It doesnt really matter where you run it from, it will recursively go through every subfolder and analyze any .java files found in those folders.

What does it generate?
It will generate the R.java file in the same folder as itself.
The R class will have the following format (you will need to add the imports).

B4X:
public class R {
        public static final class color {
                public static int material_drawer_selected_text = BA.applicationContext.getResources().getIdentifier("material_drawer_selected_text", "color", BA.packageName);
                public static int material_drawer_secondary_text = BA.applicationContext.getResources().getIdentifier("material_drawer_secondary_text", "color", BA.packageName);
        }
        public static final class dimen {
                public static int material_drawer_margin = BA.applicationContext.getResources().getIdentifier("material_drawer_margin", "dimen", BA.packageName);
                public static int material_drawer_margin = BA.applicationContext.getResources().getIdentifier("material_drawer_margin", "dimen", BA.packageName);
        }
        public static final class string {
                public static int drawer_close = BA.applicationContext.getResources().getIdentifier("drawer_close", "string", BA.packageName);
        }
        public static final class id {
                public static int icon = BA.applicationContext.getResources().getIdentifier("icon", "id", BA.packageName);
                public static int name = BA.applicationContext.getResources().getIdentifier("name", "id", BA.packageName);
        }
}

Usage?
By embedding the R.java file in your library you will be able to access resources added using #AdditionalRes.

Bugs?
It generates a lot of duplicate identifiers.
Havent really tested it in a real library.

Download?
RGenerator2:
https://www.dropbox.com/s/sri0h96u0zyjp30/RGenerator2.exe?dl=0
RGenerator Version 1:
https://www.dropbox.com/s/9vhdilztbjxxe5x/RGenerator.zip?dl=0

Credits?
@warwound for identifying this method of accessing resources.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Did you already sent it? There is no mail as yet... Ok, it´s a long way to travel for the mail ;-)
 

DonManfred

Expert
Licensed User
Longtime User
Aehm... As far as i can see; the jar does not need any R-Class

For what exactly you want to add a resource which is not needed by the wrapped jar? Or did you forget to send my the source-zip from the CEA Service?

Please give me the url of the library you want to wrap here.

Looks for me that the package is incomplete
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Yes, this string needed to get the values to configure the library.

for example:

this line in the .xml
<string name="cea_lib_broadcast_listen_port">5000</string>

this port is crucial to library can listen this udp port and used by class
CEACommunicationsLibraryAPIManager

in this line:

final String sport = context.getString(R.string.cea_lib_broadcast_listen_port);
 

MarcoRome

Expert
Licensed User
Longtime User
I tried with windows 10 and Python 2.6 ( of k remember good ) but i was message.... python24.dll etc... with Python 2.4 work without problem.
 
Top