Android Tutorial Library compilation - Compile your project to a library

Starting from Basic4android v2.50 you can compile your project, or part of it to a regular library.

Why should I compile a library?
  • Break large projects into several smaller (more maintainable) projects.
  • Build reusable components and use them from any number of projects.
  • Share components with other developers without sharing the source code.
  • Create different versions of your application (free, pro...) by referencing the same "core" library.

The output of library compilation are two files: a jar file with the compiled code and a xml file that includes the metadata that is required by the IDE.

These two files should be saved in one of the libraries folders.

Compiling to a library is quite simple. Under Project menu there is a new compile option - "Compile To Library (Alt + 5)". When you choose this option all the modules except of the main activity are compiled into a library.

SS-2013-01-01_17.18.50.png


You can exclude other modules as well with the ExcludeFromLibrary attribute (see this tutorial for more information about attributes).

The main activity and the other excluded modules can be used to test the library.

You can reference the library from other projects and access the same functionality as in the original project.

Library specific attributes

The following attributes are specific for library compilation:

Project attributes (placed in the main activity):
LibraryVersion - A number that represents the library version. This number will appear next to the library name in the libraries list.
LibraryAuthor - The library author. This value is added to the library xml file.
LibraryName (B4A v2.70) - The compiled library name. Sets the library name instead of showing the save dialog.

All modules:
ExcludeFromLibrary - Whether to exclude this module during library compilation. Values: True or False. Note that the Main activity is always excluded.

Classes:
Event - Adds an event to the list of events. This attribute can be used multiple times. Note that the events list only affects the IDE events autocompletion feature.

Notes

- You should right click on the libraries list and choose Refresh after an update when updating a referenced library..
- CallSub / CallSubDelayed - The first parameter for these keywords is a reference to the target module. When working with modules that reside in a library you should pass the module reference and not the module name as string (this is the better way to reference all modules in all cases).
- Code obfuscation - Libraries can be obfuscated during library compilation. Strings will not be obfuscated in this mode.
- Services that host home screen widgets cannot be compiled into a library.
 

Yuls

Member
Licensed User
Longtime User
Hi, Erel.
I need to serve determinate functionality of my b4a app to a Kotlin app (developed by other programmer). This programmer need a library to integrate that functionality in his Kotlin app. I not have idea of Kotlin.
If I compile to library my module, can Kotlin to accept my b4a library?
My app needs several args, do anything (using Serial lib and others) and returns a result in an string.
if not, is there any other way?
Thanks in advance.
 

Yuls

Member
Licensed User
Longtime User
So the only way to integrate my functionality with Kotlin that I see is through the Intent object using extradata to receive args and return a result , or not?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
So the only way to integrate my functionality with Kotlin
As I wrote, the standard way is to build a Kotlin library and add it to your B4A project.

I see is through the Intent object using extradata to receive args and return a result , or not?
There are all kinds of ways to communicate between two apps. Intents is one of them.
 
Top