B4A Library [Tool] Simple Library Compiler - Build libraries without Eclipse

Status
Not open for further replies.
The purpose of Simple Library Compiler (SLC) is to make it easier to build libraries. SLC is responsible for taking the Java source code files and generating the Jar and XML files.

As I see it, it can be useful in two cases:
- Creating wrappers for 3rd party SDKs.
- Modifying and extending existing open source libraries.

Do note that you still need to provide the source code. This tool only helps with the building steps.

SS-2013-06-04_19.25.38.png


How to use

Using SLC is quite simple. The main project folder should include a folder named src and optionally a folder named libs.
The Java source code files should be under the 'src' folder. Java files are saved based on the package name. So if the package is com.example then the structure will be:

SS-2013-06-04_19.29.16.png


Under 'libs' folder you can put any additional libraries that should be referenced during compilation.
The 'bin' folder will be created during the build.

When you press on the Compile button the code will be compiled and the Jar file and XML files will be outputted to the "additional libraries folder" that is set in Basic4android configuration.

Wrapper example

The attached zip file includes a very simpler wrapper that wraps Flurry Analytics library.

The source code:

SS-2013-06-04_19.37.03.png


In order to compile it (and use it) you should download their SDK and copy FlurryAgent.jar to the project 'libs' folder and to the 'additional libraries folder'.

Tips

- A simple example is included in the package (FirstLib). It is recommended to start with it.
- You can use a text editor such as Notepad++ to write the Java code.
- Tutorials about libraries development are available in this forum: http://www.b4x.com/android/forum/forums/libraries-developers-questions.32/
- There is no installer. You should just unzip the package and run the program.
- If you need to include any additional files, such as .so files, in the jar then you can create a folder named 'additional'. Any file or folder inside this folder will be added to the jar file.
- Command line mode - You can also run this tool from the command line. It expects two arguments: library name and project path.

- B4J_SimpleLibraryCompiler is included in the zip file. It creates B4J libraries.
- In order to write the library code with Eclipse you need to reference Java 7 and also reference jfxrt.jar:

SS-2013-12-02_10.01.50.png


V1.14 - Fixes an issue with running SLC from command line.
V1.13 - Added a field to set the path to Java 8 compiler (javac.exe). Should be similar to: C:\Program Files\Java\jdk1.8.0_211\bin\javac.exe
V1.12 (B4A) - source and target raised to Java 8.
V1.11 - SLC tools compiled with .Net Framework 4.
V1.10 - Adds support for the new structure of Additional libraries folder.
March 2018 - New zip with doclet v1.07.
V1.06 - Fixes the missing "bin\classes" issue.
V1.05 - Fixes an issue with old compiled class files not being deleted.
V1.03 - Fixes an issue related to B4A v5.
V1.02 - Allows usages of Java 7 features.
V1.01 - Fixes an issue with ignore field.

Download link: www.b4x.com/android/files/SimpleLibraryCompiler.zip

You should use Java 8 with SLC (at least when generating the XML).
 
Last edited:

kiki78

Active Member
Licensed User
Longtime User
I can put them elsewhere.
Java code use String variable to found binaries.
For now, I extract binaries from assets of B4A app and I put it in File.DirInternal and this work.
But I don't found this really elegant. I expect to embed binaries in library.
My question is, if I embed binaries in wrapper library by putting it in "additional" path, how can I retrieve the path where it is extract at installation, if it is extract ?
If it is not automatically extract, is it possible to extract it ?
So sorry if my question is stupid :oops:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

kiki78

Active Member
Licensed User
Longtime User
Finally I not succeed to access embedded files with ClassLoader.
Instead I put my needed files in /additional/assets/ of my wrapper class, then I add and use BA.applicationContext.getAssets() to get it.
If this can help someone with similar problems...:)
 
Last edited:

tchart

Well-Known Member
Licensed User
Longtime User
Does anyone know how to capture the output from SLC from the command line?

Ive got a batch file at the moment like this;

@echo off

SET Lib_Name=LibraryName
SET Lib_Source_Dir="%CD%"
SET B4A_SLC=D:\Basic4android\SimpleLibraryCompiler\LibraryCompiler.exe

%B4A_SLC% %Lib_Name% %Lib_Source_Dir%

This outputs the tools output to the console but for the life of me I'm unable to redirect the SLC output to a log file.

Anybody know how to do this? I'd like to write the output to a log file and then scan for errors.
 

tchart

Well-Known Member
Licensed User
Longtime User
Thanks Erel but its not working. I'm pretty proficient in batch files but just cant figure this one out.

I've tried;

LibraryCompiler.exe MyLib E:\Java\MyLib > output.txt
LibraryCompiler.exe MyLib E:\Java\MyLib 1> output.txt
LibraryCompiler.exe MyLib E:\Java\MyLib 1> output1.txt 2> output2.txt

But nothing works.

Thanks
 

tchart

Well-Known Member
Licensed User
Longtime User
Thanks Erel, that works. I'll incorporate that into my script and share when Ive tested it.
 

tchart

Well-Known Member
Licensed User
Longtime User
All, thanks to Erel here is a modified batch file that I use to compile my libraries. I use Notepad++ to edit my libraries and then just run the batch file.

Instructions
  1. To get it to work create a new batch file in your library folder (the folder above the "src" folder).
  2. Copy the code below into your batch file.
  3. Edit the path to the Simple Library Compiler (ie update B4A_SLC variable).
  4. Update the Lib_Name variable with your library name.
  5. The library source will be picked up from the directory in which you placed the batch file. This is why placing the file in the correct directory is important.
  6. Run the batch file.
  7. If successful the batch file will terminate once complete.
  8. If an error occurs the batch file window will change colour (red/white) and stay visible for 60 seconds.
Hopefully this helps someone.

B4X:
@echo off

SET Lib_Name=LibraryName
SET Lib_Source_Dir="%CD%"
SET B4A_SLC=D:\Basic4android\SimpleLibraryCompiler\LibraryCompiler.exe

echo Library Name = %Lib_Name%
echo Library Source Directory = %Lib_Source_Dir%
echo B4A Library Compiler = %B4A_SLC%
echo.

REM ------------------------------------------
REM Compile library
REM ------------------------------------------
echo.

set errorlevel=
%B4A_SLC% %Lib_Name% %Lib_Source_Dir%

IF "%errorlevel%"=="0" GOTO OK
IF "%errorlevel%"=="1" GOTO ERRORS

:OK
GOTO EXIT

:ERRORS
color FC
echo.
echo ******************************************
echo There were compile errors!
echo ******************************************
timeout /t 60 /nobreak

GOTO EXIT

:EXIT
cls
echo.
echo Done!
echo.
 

mikeeepe

Member
Licensed User
Longtime User
Being new to Java, I am not sure how to use the SLC to wrap third-party JAR files. I want to use the attached jar file to access a Pervasive database but I am not sure how to generate the xml file needed to expose the functions. Any help would be greatly appreciated.

Thanks.
 

Attachments

  • pvjdbc2.jar
    165.6 KB · Views: 260

Luk

Member
Licensed User
Longtime User
Is it possible to add an option to SLC : -target 1.6 ? Or is there another way to tell the compiler to create 1.6 compatible java files ?
(I'm using java 1.8. )
Thanks.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Erel

Getting this error when I trying to compile a project with SLC. It compiled successfully yesterday but refuses to do so today. Cannot see any strange characters in the file at line 1. Any idea how to solve this?

java:1: illegal character: \65279
 
Status
Not open for further replies.
Top