Android Tutorial Library compilation - Compile your project to a library

LucaMs

Expert
Licensed User
Longtime User


I tried again with a very simple example of two classes and it works!

I have better control of my real project.
 

Johan Schoeman

Expert
Licensed User
Longtime User
It is not different than using the original code. In your case you have created a code module, so you should write:
B4X:
MathFunc.xx

Hi Erel

I have 5 code modules inside a project named for eg A, B, C, D, E
In module A I have declared sub A1 as Public - everything else as Private
In module B I have declared sub B1 as Public - everything else as Private
In module C I have declared sub C1 as Public - everything else as Private
In module D I have declared sub D1 as Public - everything else as Private
In module E I have declared sub E1 as Public - everything else as Private
I compiled the project to a library named for eg MyLib and then refreshed the library reference inside a new project and selected it
How do I call A1, B1, C1, D1, E1 from a new project? MyLib.A.A1 does not work. A.A1 does work but only because I know that A and A1 reside inside the MyLib. If someone else compiled the library then MyLib will show in the library reference - but it seems asif the name "MyLib" is now completely unrelated to what is actually inside the library. Type just MyLib or trying to ds MyLib gives no indication of A1 to E1. But if you type dim myA as ..... then A, B, C, D, and E show in the dropdown list (and when typing dim MyA as A the
and then type "A." it will show A1 in the dropdown list). But I can't seem to find a link between MyLib and what actaully resides in A1.

Can you please explain as I am obviously doing something wrong.

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The important sentence is: It is not different than using the original code.

You call it exactly like you would have call the subs or variables if the original modules were part of the project.

The library name is never important.
If you want your library to behave like most libraries then you need to use classes instead of static code modules.
 

Johan Schoeman

Expert
Licensed User
Longtime User

Thanks Erel. I have tried the classes route too but it also seems to behave the same way. I thought it would behave as follows (regarless of the library being created via a code or class module):

Dim mlib as MyLib (and after you type "as" the dropdown list shows A1,B1,C1,D1,E1
mlib.A1

and not having to address it as

A.A1

If you for eg created the library and I downloaded it, how will I know what subs reside in the library (other than you perhaps document it somewhere in a post)? The library list will show MyLib but then if I try to do Dim MyLib it will not accept it. Unless I somehow know that A1 to A5 belong with MyLib in the dropdown list it will not be possible to now that it is in actual fact the case.
 

Cableguy

Expert
Licensed User
Longtime User
Hi Guys...

I'm trying this "compile to lib" stuff for the first time and need help...

I need help on events.

Take this code"

B4X:
Dim TT as test 'this will be my lib

TT.initialize(bla,bla,bla)

Now the "I need help" part"
B4X:
Sub TT_MyEvent
log("FIRE")
end Sub

I want the event to be fired to the main activity from within a sub in my lib...
like...
B4X:
........
if x+a+r <> 254658 then
'Call MyEvent in Main
else
......
end if
.............
....
How do I do THAT?
 

Cableguy

Expert
Licensed User
Longtime User
Thanks NJ!!!

I knew I had to pass my lib as an object, I just couldn't see how...
Now I can start my real work!
 

Cableguy

Expert
Licensed User
Longtime User
One last question...

If my Lib has NO GUI interaction, can I surpress the Activity attribute in the initializer?
 

Cableguy

Expert
Licensed User
Longtime User
Another Question...

Is it possible to create multiple libs around the same "external" object and use them in the same app?
Being more concrete...
I aim to build a series of helper libs that target the IOIO lib.
I am going to create one to handle connecting to the Board, and then a few more to do specific tasks...
I guess I need to pass the IOIO object from the first lib to the others, creating a two level hierarchy... but How?


IOIO External LIB
|
|
MyConnection Manager LIB
| | |
Helper#1 Helper#2 Helper#3
Is this even possible?
 

hanyelmehy

Active Member
Licensed User
Longtime User
I compile a library that include activity with GUI and modules ,but when i add this library to my project (i add library asset files to my project asset files)
i get this error when start library activity
java.lang.RuntimeException: Object should first be initialized (Activity).
Did you forget to call Activity.LoadLayout?

i am able to run library as a normal project without problems

Note :When Test Again I Found
-its work if use release mode
-i am not enable to add any thing relate to library activity in my project manifest
for example i need to set screenOrientation using
SetActivityAttribute(library activity name, android:screenOrientation, "landscape")
but i get error when make Compiling :
Compiling code. Error
Module: library activity name not found.
 
Last edited:

hanyelmehy

Active Member
Licensed User
Longtime User
There is an issue with the debugger and compiled activities. You can implement the logic and UI with classes instead of activities (like done in AnotherDataPicker and other custom views).
Thank you for answer ,any other idea for manifest issue
also i think its better to make calls using library name (libname.moduelname) ,in this case it well be more clear ,and well not make conflict with project modules names that use this library
 

opus

Active Member
Licensed User
Longtime User
Another great feature, thank you Erel!

I had one problem (Stupid.me). I searched for the created two library-files in project folder and found only the .xml.
I wouldn't have thought that they were already saved in the folder for additional libraries.
 

Dipak Dahake

New Member
Licensed User
I cannot instance the class which I have compiled to library.
No class is shown with Dim in the testing Project.
Please help.
 

MarcoRome

Expert
Licensed User
Longtime User
Hi all.
it's possibile use #AdditionalJar ??
Thank you
Marco
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…