Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon
Accepted Solution

Can libraries be loaded only when it is required?

I am running into a problem where the library used by the application gets loaded when the application is started by the user.  I was expecting it happens when the application actually executes the following code.

LibIFace LI = (LibIFace) Class.forName("LibIFace").newInstance();

 This is not the behaviour I want. Is there a work around?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Can libraries be loaded only when it is required?

What problem is this causing you?

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Can libraries be loaded only when it is required?

The library uses OS version specific APIs, and this leads to the application cannot be started on certain devices with lower OS versions even though higher OS version APIs are not all called.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Can libraries be loaded only when it is required?

The approach you are using where you reference the cod using Class.forName("..") should work OK and allow your two cods to exist independently.  So there is no problem with this code, you have something else that is causing the problem. 

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Can libraries be loaded only when it is required?

By this link

http://supportforums.blackberry.com/t5/Java-Development/Develop-applications-for-different-BlackBerr...

 

[quote]

Using libraries to support incremental functionality

 

In situations where the application needs to support increased functionality on later BlackBerry Device Software versions, but where the previous functionality is still valid, a slightly altered approach can be used with dynamically loaded libraries. For example, the application may implement some base features, while additional libraries add capability that works with the original application. The main application dynamically loads any libraries that are present, and the right collection of libraries is installed based on the BlackBerry Device Software of the BlackBerry smartphone. As before, the main application and interface library must be built in the earliest BlackBerry JDE version, while each library is built in the appropriate BlackBerry JDE version for the APIs accessed.

 

[/quote]

 

This mean multiple installs.

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Can libraries be loaded only when it is required?

Sorry I am being thick here, but I'm not sure how that helps with your problem.  That is the theory, the theory works, so if your application will not run without the Library, then you have some reference into that Library in your application.  You need to break that link in order for this approach to work. 

 

Designing a structure like this takes some thought.  As one option, consider this structure that requires 3 cods:

 

a) Your main application cod that will run, but which can use libraries if they are present. 

 

b) An interface Library, that is a separate cod and contains the base interfaces that your special classes will implement.  Your main application will be dependent on this.

 

You should be able to run your Application with just (a) and (b) present on device. 

 

c) Your OS level specific Libraries.  These will be dependent on the Interface Library (b),

Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Can libraries be loaded only when it is required?

I may be wrong, but from what I've observed, the JVM does some sort of mapping of the classes and methods referenced in the application at load time regardless of whether or not the program logic actually uses the libraries during runtime. So if your application uses any libraries that aren't available in that OS version's API, then you get the error you are seeing. I don't think there is any way to get around this "pre-mapping" of the application's classes.

 

I think the obvious approach is to have multiple CODs which I have no experience with.

 

Scott

 

 

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Can libraries be loaded only when it is required?


superdirt wrote:

I may be wrong, but from what I've observed, the JVM does some sort of mapping of the classes and methods referenced in the application at load time regardless of whether or not the program logic actually uses the libraries during runtime. So if your application uses any libraries that aren't available in that OS version's API, then you get the error you are seeing. I don't think there is any way to get around this "pre-mapping" of the application's classes.

 

I think the obvious approach is to have multiple CODs which I have no experience with.

 

Scott

 

 


This is exactly what I am dealing with. I want to have a single code base for all the OSs.  I have the OS dependent stuff implemented in a library, and built it with the more recent JDE.  I use the OS version to determine if the library should be loaded or not in the main application which is built with a much eariler JDE. The problem is. On the devices running older OSs, the application does not even start.

Developer
Posts: 709
Registered: ‎09-10-2009
My Device: 8520, 8900, 9000, 9300, 9650, 9700, 9780, 9800, 9810, 9900, 9930
My Carrier: Verizon

Re: Can libraries be loaded only when it is required?

Problem Solved.

 

Create a separate library project just for the interface (no implementation) for the main application and all the libraries to use.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Can libraries be loaded only when it is required?

I can confirm that the JVM does make sure that classes and methods used in a cod are available on device.  If they are not available, then the cod is not loaded.

 

The structure that you have adopted, with the interfaces in a separate cod, is exactly what I suggested previously. 

 

The BBM dependency checker uses a variation on this approach, if you want another example of the process.