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:

fishwolf

Well-Known Member
Licensed User
Longtime User
I have compile the library sample "FirstLib", tool add library to B4J librarries folder and B4J see this library.

How to i can use the library (single method add)?
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Erel , can you please add a recent menu so we can load last worked-on projects data (Project Folder ,Library Name , and b4ignore ) fields easily ?
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
SLC can be run from the command line. You can create batch files to automate it.
Sorry for asking too much
- Command line mode - You can also run this tool from the command line. It expects two arguments: library name and project path.
Can we pass b4ignore too ?
Also Should we pass it directly like librarycompiler "C:\Users\user\Desktop\libswrapping\twitter4j" "SMMTwitter4J" ?
Thanks in advance
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Can we pass b4ignore too ?
No. But it shouldn't matter. Set it once with all the prefixes required.

Also Should we pass it directly like librarycompiler "C:\Users\user\Desktop\libswrapping\twitter4j" "SMMTwitter4J" ?
The first parameter is the library name and the second if the project path.
 

rbirago

Active Member
Licensed User
Longtime User
I need to develop some wrappers so I started to inspect all the online docs.
First of all I followed the good YouTube tutorial


that explains step-by-step how to create a simple library.

All was ok, but...when I run the B4A test program (the same few lines of the tutorial) it gives me this error:

B4A version: 6.00
Parsing code. (0.00s)
Compiling code. (0.06s)
Compiling layouts code. (0.01s)
Organizing libraries. (0.00s)
Generating R file. (0.67s)
Compiling debugger engine code. (1.48s)
Compiling generated Java code. (1.68s)
Convert byte code - optimized dex. Error
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:598)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:570)
at com.android.dx.command.dexer.Main.access$2(Main.java:546)
at com.android.dx.command.dexer.Main$2.processFileBytes(Main.java:514)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:537)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:449)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:236)
at com.android.dx.command.dexer.Main.run(Main.java:206)
at com.android.dx.command.dexer.Main.main(Main.java:179)
at com.android.dx.command.Main.main(Main.java:103)
...while parsing anywheresoftware/b4a/sample/FirstLib2.class
1 error; aborting

Any suggestion?

Thank you

P.S: Using B4A 6.0 , Java JDK 1.8.0_91 and platform Android-23
 

DonManfred

Expert
Licensed User
Longtime User

pxpto

Member
Licensed User
Longtime User
I need to compile my library with Java 6.

I've read a post from Erel suggesting to configure B4A to use Java 6 and set "-b4aignore aaa -target 1.6". When I do that I get an error. It's still looking for Java 7:

upload_2016-10-14_9-59-55.png


Could someone help me please?
 

Attachments

  • upload_2016-10-14_9-59-52.png
    upload_2016-10-14_9-59-52.png
    20.8 KB · Views: 321
Status
Not open for further replies.
Top