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:

thedesolatesoul

Expert
Licensed User
Longtime User
Thanks, my gitlab account is gdbgeek.
Added.

Regarding the package name, can you just add a place holder package name as a reminder? Maybe "package com.remember.to.update.the.package.name"?
Hmm...I consider that more dangerous than no package, as it can go undetected at compile time.
Instead I can add a comment there? Why would you prefer to have a dummy package name?
I usually develop in Eclipse and it flags it straight away, so I get to do a quickfix on it.
 

DonManfred

Expert
Licensed User
Longtime User

tchart

Well-Known Member
Licensed User
Longtime User
Why would you prefer to have a dummy package name?
I usually develop in Eclipse and it flags it straight away, so I get to do a quickfix on it.

I develop most of my Java code in Notepad++ and use SLC to compile. The error message with no package name is misleading and doesnt give any clues as to the fact that the package name is missing.

All it says is the following;

B4X:
E:\Dropbox\My Apps\Java\MD\src\com\afollestad\materialdialogs\R.java:5: error:
duplicate class: R
public class R

I guess a comment would do.
 

thedesolatesoul

Expert
Licensed User
Longtime User
I develop most of my Java code in Notepad++ and use SLC to compile. The error message with no package name is misleading and doesnt give any clues as to the fact that the package name is missing.

All it says is the following;

B4X:
E:\Dropbox\My Apps\Java\MD\src\com\afollestad\materialdialogs\R.java:5: error:
duplicate class: R
public class R

I guess a comment would do.
If you read my reply in the other thread, you will appreciate how important it is to get the package name correct.
I think a comment is not going to help either, but it is easy to add. I really do want the compile to fail if there is no packagename, because if it doesnt, it will lead you to more confusing errors and more wild goose chases.

(Currently i've stepped down my dev work due to pressing domestic issues, so im not sure when i will be able to get back to it)
 

DonManfred

Expert
Licensed User
Longtime User

thedesolatesoul

Expert
Licensed User
Longtime User
How about now? *rolling eyes* ;-)
Sorry still no real active development. To be honest it would take me a loooong time to open my home PC.
However I would probably take a different route this time
B4X:
C:\OldPC\Other\Android\android-sdk\build-tools\18.0.1>aapt package --non-constant-id -f -m -M test\man\AndroidManifest.xml -S test\res -I c:\oldpc\other\android
\android-sdk\platforms\android-17\android.jar -J test\ --generate-dependencies
 

ArminKH

Well-Known Member
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.
hi it seems this tools has a issue on Windows 10
i haven't any problem on window 8 but this tool can't create R.Java file on Windows10
upload_2016-1-6_16-3-41.png
 
Last edited:

ArminKH

Well-Known Member
Have you checked your antivirus/firewall? Maybe this is preventing something... Seems that a dll which will be extracted at runtime is missing.
Maybe try to start R-Generator as Admin
my antivirus is disable and R-Generator ran as administrator but still i have same problem
is Rgenerator.exe written by phyton?
 

ArminKH

Well-Known Member
Looking for solution about 1 day without result
still i have problem:)
@Johan Schoeman
upload_2016-1-8_1-19-0.png
 
Last edited:
Top