Fire Android Class Library Question

I have a small Silver Android Application. I want to refactor some of the code into a Library so that it is cleaner. I added an Android Class Library to the workspace and named it ‘Library’ and put some code in it, and everything compiles okay.

I then go back to the app and try to do an ‘import Library’ but when I build it cannot find this module/framework. I did check the default namespace setting as referred elsewhere in the forums, and it is set to the right name.

Is there a ‘trick’ to be able to import the Android Class Library into the main application section?

Thank you,
Tyler

Did you add a reference tp the library as well?

There’s two parts to using external classes.

The first is the reference, where yo tell your project, “hey, also grab stuff from these other .jar files”. Your Class Library project compiles to a plain .har file you can just reference. The easiest way to do this is right-click the class library project and choose 'Show Output in Finder" and than drag that jar onto your main project.

The second is the “import” clause in your code. that just tells the compiler “when you see a short class name such as Foo, also look for classes that are i these namespaces”.

Does that make sense?

This docs topic explores this in a bit more depth: https://docs.elementscompiler.com/Oxygene/Delphi/NamespacesAndReferences/

yours,
marc

Sorry, perhaps more detail will help: I am adding a Silver Cooper Class Library to my solution, and I want to use that in my main Android application module. I set the app module as 'Depend’ing on the class library, and do an ‘import LibraryName’, but I get an error on the import line of ‘Unknown namespace’. I do have the namespace set in the class library settings, and I see the generated LibraryName.jar in the bin/Debug output.

I have it set up currently as a Shared Project, but I would like to actually force clients to use an import statement, instead of just assuming everything should be included in the parent project.

I am using the released Fire 9.1.99.241 btw.

Thank you,
Tyler

Does the project compile if you just add the reference?

Add an empty project and remove it after successfully having included the library into your project. Then the whole ‘solution’ is saved and the meta information should be available. (Emulation a Save all or Save everything).

I’m not sure if this solves your issue but I implemented a test library (OS/X) and the situation looked pretty similar to your ‘troubles’ first. Honestly I’m not sure why it worked, but I could at least repeat the process.

Maybe I personally also don’t have understood the process of importing libraries.

I think the idea of importing a library and a ‘stub’ is pretty different from referencing a package or an assembly.

I tried adding an empty project and removing, but same result. I cannot use the class from the library either directly or with an import (and code completion does not even give me the option to select my library).

I will keep working with the Share Project approach until I hear of another idea.

Thank you,
Tyler

Sounds strange.

I just have an OS/X Project since we both use the same version of the Fire IDE.

A few minutes ago …

a) I created a shared library project
b) Added a function
c) compiled the projects
d) created a reference to the library (Browse in Add References) located in the bin/release subdirectory
e) The library is imported but shows a red circle with an icon
e1) Maybe I did make the hint path absolute
e2) In this state the compiler already knows about the library and the symbols found there but does not know the symbols in Intellisense
f) compiled
g) did the trick with adding the ‘empty’ project
g1) compiled
h) Now Intellisense knows the symbols both the function and the namespace.
i) Every change in the library is reflected correctly in Intellisense from now on - adding functions, classes, methods …

The message with the wrong namespace, iirc, showed up when I used the fx file from the obj directory or the hint path was not absolute. (I hope I remember correctly).

// Sorry that I don’t remember the step with the hint path. Because making the hint path absolute did not help with the ‘wrong’ fx file.

That worked.

is the main app done in Elements as well. or in ADS?

note that setting “Depends on” is not the same as adding a reference. it just affects the compile order. it sounds to me like you’re still missing the reference.

Here is my project tree: I have both SharedFoundation (a Shared Project) and Foundation (a Class Library) referenced in the main app (via a drag and drop operation). The Shared Project code is accessable of course, but the classes from the Class Library are not.

Thanks,
Tyler

ok, that looks good, except for the yellow warning icon. that means it can’t find the jar. does it show any error i the main. ore, if you select that reference? can you zip the whole thing up and send me a copy?

(side question, why do you have a shared project AND a library?

I would love to zip and send a copy, but not via the mailing list. It is not quite ready to share yet. :slight_smile: I will put on dropbox or drive and share with you?

  • Tyler

side answer: i could not get the class library working as expected, so i used the shared project just to continue coding…

Thanks,
Tyler

Imo the yellow icon stays even if the compiler already knows how to ‘link’ the symbols. I think the Fire IDE simply did not load the symbols or maybe didn’t add the list of paths where the libraries can be found. Just a thought.

Okay, I found the issue, based on something Michael said: if I Add Reference / Browse to the .jar in Lib/Debug, then it finds everything okay. But if I drag from the class lib to the references section, the build fails. So it looks like an issue with drag and drop in the Fire IDE (the path to the lib looks the same in both cases).

Thank you both for your assistance. Now I can hopefully kill that SharedProject.

  • Tyler

Sure, just mail the the details directly, mh@remobjects.com.

Yes, in some cases the compiler can see a reference Fire doesnt; but clearly it didn’t in this case, so checking the error is a good first step :wink:

Curious. dragging the project should have created a project reference with a different icon. Mono is picky about project refs, which is why i recommended dragging the jar from Finder. Can you still send me the project(s) as they are now so i can try and reproduce there issue?

thanx!

Uploading and will share soon. Thanks! I left it in a working state. All you need do is remove the Foundation reference and then try the drag and drop.

1 Like

thanx, will hae a look in the morning!

It’s ok. I’m personally pretty happy that once Fire recognizes the ‘stub’ or metadata exposed that the IDE gets to know the new symbols found too, which is a great advantage. In the world of the package libraries this sounds just ‘normal’ but in the world of libraries the story is pretty different.