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:

mkvidyashankar

Active Member
Licensed User
Longtime User
I am trying to create a library using a jar file.
I am getting this error.
I am very new to java.
please guide me

Starting step: Compiling Java code.
javac 1.6.0_27
H:\My Disc\android projects\library sources\Filters (1)\src\com\jhlabs\composite\AddComposite.java:19: package java.awt does not exist
import java.awt.*;
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error


Error.
 

pierosso

Member
Licensed User
Longtime User
is there anyone able to write a library for a native facebook login?
the new way to log in inside your application using facebook with just a messagebox without webview?
thanks
 

Informatix

Expert
Licensed User
Longtime User
The zip file in post #1 was updated with doclet tool version 1.04.
This doclet v1.04 has the same bug than the version I tested a few weeks ago. When I generate the XML file of libGDX with it, for example, I have two functions missing in the result (set, getEndPoint), and two are added (draw, get) despite they are hidden with @BA.Hide. With the previous doclet (v1.02), it was possible to get the right result with a workaround for some cases. With this doclet, I can't see a solution.
 
Last edited:

Nickle

Member
Licensed User
Longtime User
I am getting error below when trying to use SLC. I know I have something basically wrong. Java code below.. I need help..

Starting step: Compiling Java code.
javac 1.7.0_03
javac: directory not found: bin\classes
Usage: javac <options> <source files>
use -help for a list of possible options
Error.


B4X:
package anywheresoftware.b4a.PhoneSMS1;

import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.*;
import android.telephony.*;


@Version(1.0f)
@ShortName("PhoneSMS1")
@Permissions(values={"android.permission.SEND_SMS"})
public class PhoneSMS1 {

    /**
    * Sends an SMS message. Note that this method actually sends the message (unlike most other methods that
    *create an intent object).
    */
    public static void Send(String PhoneNumber, String SMSC, String Text)

    {
        SmsManager sm = SmsManager.getDefault();
        sm.sendTextMessage(PhoneNumber, SMSC, Text, null, null);

    }
}
 
Last edited:

acharya1981

New Member
Licensed User
Longtime User
When I try to compile any eclipseproject folder in Simple Library Compiler - to generate B4A Library - it does compile correctly - but when - Loading generated lib in B4A - it always shows some error - for all different projects - as - some_package.some_class.some_child - already exists - there is no use of using @hide even - help ....
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
Hi Erel,

I have been trying to implement some missing functionality in the Google Play Services wrapper that NFOBoy created earlier this year. I loaded the project into Eclipse, implemented the missing functions & then fixed all the errors Eclipse was telling me about. All good - except when I try to compile using SLC, I get this error:

Starting step: Compiling Java code.
javac 1.7.0_25
C:\Users\Colin.Smith.DOMAIN\workspace\GoogleGameHelper\src\b4a\game\helper\AchievementWrapper.java:3: error: package com.google.android.gms.games does not exist
import com.google.android.gms.games.Player;
^
1 error


Error.

At first I thought it was something weird with gms.games - however I've realized that this is the first call to an external .jar file in the first code module, so I'm thinking it's a configuration issue, but I don't know what. I've attached a screenshot so you can see the setup in Eclipse, but it all seems good to me, so am I missing something in SLC?

Thanks - Colin.
 

Attachments

  • screenshot.png
    screenshot.png
    290.7 KB · Views: 452

Computersmith64

Well-Known Member
Licensed User
Longtime User
EDIT: OK - I've got it sorted now. I should read instructions more carefully... Thanks!
 
Last edited:

B4JExplorer

Active Member
Licensed User
Longtime User
Intellij doesn't have the custom doclet option that Eclipse does, so tried to use the command line for SLC.

LibraryCompiler.exe JarClassLoader c:\Projects_Programming\Intellij\JCL


, but it tells me


Additional libraries folder must be set in the IDE,


.... scratch that. I was using the Basic4Android command line, and should have been using the B4J_LibraryCompiler.exe.

I might upload the project, if any further problems.
 
Last edited:

B4JExplorer

Active Member
Licensed User
Longtime User
Been at this for so many hours, can't think straight anymore.

Attached is the Intellij project folder. If anyone wants to give this a try, and generate the jar and xml for the project, please share it with everyone.

Otherwise, I'll figure it out tomorrow, and post it for the B4J community.

Couldn't fit it within our 512 KB limit, but log4j-1.2.14.jar or a later log4j version, should also be in the lib folder.

The library itself is from https://github.com/kamranzafar/JCL
 

Attachments

  • JCL.zip
    344.8 KB · Views: 492
Status
Not open for further replies.
Top