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.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:

ac9ts

Active Member
Licensed User
Longtime User
I'm not sure what I need to expose yet since I can't get the library built to build an app. What do I need to do to hide everything so the library builds? Once I get it to built, I can then go and start exposing methods and properties.

The library I'm trying to wrap is the Chromecast Companion Library (https://github.com/googlecast/CastCompanionLibrary-android
 

SigneFurax

Member
Licensed User
Longtime User
Hello all,

As I use B4A mostly to quickly wrap java classes into Android applications, I was very interested in SLC, but I encounter a funny problem. Testing it on the FirstLib example, everything seems OK (no errors & both jar&xml are created in the proper directory. What happens is that he jar file is OK, but the xml file always contains just a header with no class information

<?xml version="1.0" encoding="UTF-8"?>
<root>
<doclet-version-NOT-library-version>1.04</doclet-version-NOT-library-version>
</root>

I’ve tried a few things (moving both code, and SLC to no-space directories, fooling around with annotations, using an older BADoclet version) ...to no avail. Nevertheless, when I create the lib the old way (with Eclipse), javadoc creates the complete xml file and the lib works fine. Using the SLC-Jar and the Javadoc xml also make the lib work fine in B4A. I haven’t used B4A for quite a long time, and upgraded recently to v5.20, so I guess I may have some bad config somewhere. Do you have any ideas about this? I thank you in advance
Cheers
 

SigneFurax

Member
Licensed User
Longtime User
That was it.
Reading from previous posts that it should not be left blank, I had left the -b4aignore field untouched from the downloaded example. Suppressing all did the trick.
Sorry for the stupid question, and thank you for your quick answer.
SLC is a real treat...
Cheers
 

ArminKH

Well-Known Member
@Erel
is this possible to add an option (maybe in future) to obfuscate compiled lib? same as b4a obfuscation ?
 

Johan Schoeman

Expert
Licensed User
Longtime User
How do I get SLC to point to javac 1.7.0_79 and not to javac 1.6.0_15? I have both version installed but SLC keeps on using javac 1.6.0_15. I notice in another post that there is a "ini" file that needs to be edited and changed but can't find any such file...

EDIT: Solved - sorted it out.
 
Last edited:

wimpie3

Well-Known Member
Licensed User
Longtime User
I'm getting the following error:

B4X:
error: lambda expressions are not supported in -source 1.7
(use -source 8 or higher to enable lambda expressions)

I've modified the -b4aignore field and added this: "xxx -source 8" but the problem remains...
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Well, this happened during the compilation of an Android library... so I'm kind of lost here...
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Unfortunately there are no jar's available for the library I want to use.
 

fransvlaarhoven

Active Member
Licensed User
Longtime User
Hello,

I'm using SLC to build a wrapper for external .jar files.
The external library needs several .jar files.
When I put all those .jar files manually into a single .jar-file and use

@DependsOn(values={"singlefile-pgplib-android"})


it works.

Is it also possible to set all the external .jar files so that I don't have to do that manually or is SLC only working wit a single .jar file?

Thanks,
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi Erel ,
Can SLC be improved to show warnings ?
A library compiles fine but with lines like these :

finish: C:\AdditionalLibs\Mylibname.xml
4 warnings

Completed successfully.
I don't like Eclipse nor Android Studio :D
 
Status
Not open for further replies.
Top