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:

xiaoyao

Active Member
Licensed User
Longtime User
Hello Thank's for the reply
I'm sorry I took the source code from here http://www.chilkatsoft.com/download/chilkat-9.4.1-android-rsa.zip
I don't know where to put the version info.
But I edit the chilkat.java and put the following

package com.chilkatsoft;

import anywheresoftware.b4a.BA;
//import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@Version(1.0f)
@ShortName("chilkatsoft")
//@ActivityObject
//@Author("chilkatsoft")


............
..And the version does not appear thank's for considering myself
Best Regards
View attachment 22912
i has this error ,how to fix?
 

thedesolatesoul

Expert
Licensed User
Longtime User
It creates a string with all the java files and calls javac to compile it. The string is created dynamically so it is not simple to post it.
I was afraid of that.
Are you willing to open source it on github so i can fork it?
Or alternatively, I guess I need to do a .java file traversal, I can write a script in Python to do that.
Thanks
 
Last edited:

klarsys

Active Member
Licensed User
Longtime User
I recently updated B4A to v4.30

Now, when I try to compile a library, I get this error: package anywheresoftware.b4a does not exist

I have added android.jar, B4AShared.jar and Core.jar in referenced libraries.

What could go wrong?

I updated SLC also to v1.02, still get the same error.
 

klarsys

Active Member
Licensed User
Longtime User
You don't need to add these three jars. They will be added automatically.
Still get the same error.
If I do so, Eclipse starts showing numerous errors.

By the way, I get these error for library projects that were compiling earlier.

Does the library compiler exchange any information with B4A?
 

xiaoyao

Active Member
Licensed User
Longtime User
I recently updated B4A to v4.30

Now, when I try to compile a library, I get this error: package anywheresoftware.b4a does not exist

I have added android.jar, B4AShared.jar and Core.jar in referenced libraries.

What could go wrong?

I updated SLC also to v1.02, still get the same error.

sometimes ,i use "netbeans" software to compile a library,it will show all error,and can fix it.because it's a very good ide for write java project.i can make it to jar,but it's hard to create the xml file.so how did i do? i create a empty jar project the same name like my library ,only with the method,so it make xml file quick,so i make jar by real java code ,and make xml file by netbeans.

in fact my jar with about more Hundreds of classes.it also can't compile with "LibraryCompiler.exe"
some times ,LibraryCompiler.exe can't compile some project,if classes is tool big.
netbeans setup ok with 628 MB disk size.you can try.


Your question I concrete is less clear. These are some of my development experiences, for reference only. If you need this, also can come to ask me.
 

klarsys

Active Member
Licensed User
Longtime User
SLC takes the path to android.jar and to B4A core libraries from the IDE ini file.
I feel SLC is not able to find B4A libraries. Is there any way I can debug it?
Is anything case sensitive by any chance?
 

klarsys

Active Member
Licensed User
Longtime User
Can you post the full message from SLC window?

Sure:

B4X:
Starting step: Compiling Java code.
javac 1.8.0_05
D:\klarsys\b4alibs\WifiManager\src\com\klarsys\b4a\WifiManagerWrapper.java:5: error: package anywheresoftware.b4a does not exist
import anywheresoftware.b4a.BA;
                           ^
1 error


Error.
 

klarsys

Active Member
Licensed User
Longtime User
Also attaching Eclipse project, I just started with it.
 

Attachments

  • WifiManager.zip
    4 KB · Views: 304

klarsys

Active Member
Licensed User
Longtime User
I confirm it is LibraryCompiler.exe

I did some hacking to find that it uses following argument when compiling, which indicates some issue with getting B4A path:
B4X:
-sourcepath src -cp "C:\Windows\system32\OpenWith.exe\../libraries\B4AShared.jar";"C:\Windows\system32\OpenWith.exe\../libraries\Core.jar";

I don't know how it gets "C:\Windows\system32\OpenWith.exe", if you can share some insights, it can be fixed.
 
Status
Not open for further replies.
Top