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:

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Erel,

Can you know why not find my classes? Look in my sample, please!


I create a simple library based on GDK.JAR (Google Glass SDK Sneak Peek)
When I compile throught SLC, is ok, no errors, but when I try to use, ocurrs this error


** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: com.google.android.glass.app.Card
at com.visualnet.library.livecard.Initialize(livecard.java:32)
 

Attachments

  • SimpleLibraryOK.jpg
    SimpleLibraryOK.jpg
    84.6 KB · Views: 304
  • LiveCard.zip
    17.1 KB · Views: 297
  • TestLib.zip
    5.9 KB · Views: 326

ppgirl

Member
Licensed User
Longtime User
Hi Erel,

I want add option "-encoding utf-8 -charset utf-8 " when making javadoc , but where can I add ?

I need change charset for support utf-8 Chinese . thanks!
 

ppgirl

Member
Licensed User
Longtime User
Thanks ,

It has same problem while ignore field fill "org,com.android,com.example,com.hoho -encoding utf-8 -charset utf-8 "

Which can I set option when creating XML?

Starting step: Compiling Java code.
Completed successfully.
Starting step: Creating jar file.
Completed successfully.
Starting step: Creating XML file.
D:\work\SimpleLibraryCompiler.cul\cul\src\org\freyja\libgdx\cocostudio\ui\BaseWidgetParser.java:16: 警告:编码 GBK 的不可映射字符
* 鎺т欢 杞崲鍣?
^
D:\work\SimpleLibraryCompiler.cul\cul\src\org\freyja\libgdx\cocostudio\ui\BaseWidgetParser.java:30: 警告:编码 GBK 的不可映射字符
/** 鍏叡灞炴?瑙f瀽鍣?*/
 

Gunther

Active Member
Licensed User
Longtime User
Hi Erel,

I am getting stucked with this Libary. It gets created without any errors or warnings. It gets also fine in the IDE. But when I chose that in the LIBs than it gets (loading..) and ... nothing anymore. No showing of version number etc.

What is may be wrong?

Ciao,

Gunther
 

Attachments

  • achartengine.zip
    130.1 KB · Views: 299
  • AChartEngine JAR XML.zip
    88.3 KB · Views: 278
Last edited:

mnf

New Member
Licensed User
Longtime User
Hi,

Just trying out the Library Compiler and struggling to get even the FirstLibrary to compile:

Alternates between:

Starting step: Compiling Java code.
javac 1.7.0_07
E:\Program Files (x86)\Anywhere Software\Basic4android\Libraries\FirstLibrary\src\com\example\FirstLib.java:3: error: package anywheresoftware.b4a does not exist
import anywheresoftware.b4a.BA;
^
1 error

and

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


Error.

Have (full) version of b4a installed on E: in Program Files (x86)\Anywhere Software\Basic4android and this works well - extracted Library compiler to the b4a directory after trying on D: (with same results).
I guess a path problem:

javac.exe E:\Program Files\Java\jdk1.7.0_07\bin\javac.exe
android.jar D:\Android\adt-bundle-windows-x86_64\sdk\platforms\android-17\android.jar
Additional libraries E:\Program Files (x86)\Anywhere Software\Basic4android\AdditionalLibraries
Shared modules -----

Any suggestions gratefully received.....
 

daemon

Active Member
Licensed User
Longtime User
The first one probably indicates that you haven't added atleast one of the three .jar files to your project: B4Ashared.jar, Core.jar, android.jar

I get the 2nd error in almost every alternate click to 'Compile' button. Just ignore it and click again.
 

mnf

New Member
Licensed User
Longtime User
Many thanks for the quick response.... Copy B4AShared.jar and Core.jar to the FirstLibrary/libs directory and compilation success :)

Now to try Flurry!
 

mnf

New Member
Licensed User
Longtime User
Yes - that works too! Added FlurryAds-4.2.0.jar and FlurryAnalytics-4.2.0.jar

Now to try adding some more functionality to IceFairy's wrapper to the Zxing library to try and get camera output into a panel instead of full screen. That's a story for a different thread.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Will SLC accept this structure to be compiled?

FirstLibrary
libs
a.jar
b.jar​
src
com
example
blabla_1
a1.java
a2.java
a3.java​
blabla_2
b1.java
b2.java
b3.java​
blabla_3
c1.java
c2.java
c3.java​
 
Last edited:

kiki78

Active Member
Licensed User
Longtime User
Hi Erel,

I try to wrap FFMPeg using this project https://github.com/guardianproject/android-ffmpeg-java.
For native et java parts seems it's ok, but I have problem with Simple Library Compiler and Auto generated java files.

I receive this message in SLC logs:

... package org.ffmpeg.android does not exist
import org.ffmpeg.android.R;

^
1 error

Have you some idea ?

Ffmpeg project.png

Regards
 

kiki78

Active Member
Licensed User
Longtime User
Thank you Erel,
I think I'm going in bad way, as I try to modify original java source to directly compile it for B4A.
I change that and create new library to wrap original.

This begin to work...
My last problem is for ffmpeg executable distribution.
For now I put it in B4A project assets files and extract it at start of application. But it's not very clean !

I try to put it in "additional" directory in my wrapper library project, but I don't know how to found the correct path where this files are copied on devices. For example, may I extract this path from ba.context ?

Regards
 

kiki78

Active Member
Licensed User
Longtime User
This is android executable, usable, for example, in console, like ffmpeg on other OS.
I need to know where it is to call it from java code.

Originally, this file is included in resources of java library in res/raw and extract the first time in constructor.
But as I'm really poor in java/eclipse this never work and I don't understand why !
Seems this is due to my previous problem with auto generated R.java.
I receive message "don't find resource xxx".

So I modify that and try to include it in "additional" path of my wrapper class, that seems to be made to embedded additional files.

Regards,
 
Status
Not open for further replies.
Top