5

I want to import facebook libraries for blackberry 5.0 and above and don't want to import those libraries for 4.6 and 4.7.

I tried to use preprocessors for 4.7 and above by following below link: http://smartfone-more.blogspot.in/2010/05/coding-for-multiple-blackberry-devices.html

now its working fine with JDE 4.7 but not getting expected result for 5.0. Please find the code below which i tried:

//#ifdef JDE_4_7_0
import net.rim.device.api.ui.component.ButtonField;
//#else
import net.rim.device.api.ui.component.LabelField;
//#endif
import net.rim.device.api.ui.container.MainScreen;


public class TestScreen extends MainScreen{

        TestScreen(){

                //#ifdef JDE_4_7_0
                ButtonField btn = new ButtonField("Test Button");
                add(btn);
                //#else
                LabelField lbl1 = new LabelField("Test Label 1");

                add(lbl1);
                //#endif
        }
}

As per the code i am expecting the result written in else part for 5.0 and if part for 4.7. I checked it on device as well as JDE both.

Please Help.

Adil Soomro
  • 36,617
  • 9
  • 98
  • 146
SB24
  • 125
  • 1
  • 8
  • 1
    Are you using JDE for final builds? if so you have to build it once with preprocessor flag to get code file for lower oses. Save it somewhere. And after you have to remove preprocessor flag from JDE build options and build it for higher oses – Eugen Martynov May 03 '12 at 11:24
  • http://stackoverflow.com/questions/10445072/which-build-to-be-considered-for-use-when-a-preprocessor-is-used check out this post too – Yatin May 04 '12 at 10:22

2 Answers2

3

First of all, the JDE_4_7_0 tag is a custom tag you should define in BlackBerry project properties -> "Compile" tab -> preprocessor defines. You can give it the name you wish.

Second, in your source file, the first line (even before package declaration) should be:

//#preprocess

Then, when you want to disable the conditional import, go back to the "preprocessor defines" tab and remove the JDE_4_7_0 entry. That will make the compiler enter the #else clause. The BB plugin for eclipse does not detect the OS, it is all an artifact you should control.

EDIT:
You'll end with two sets of deliverables, one for 5.0+ and the other for 4.x. BBant tools allows you to perform the compilation process in one step, but the product of the compilation will be the same. As an alternative, you can:

  • try to include FacebookBlackBerrySDK-vx.x.x.jar and Log4B-vx.x.x.jar (be sure these are preverified) in a 4.6 project. I was able to include these jars and compile a 4.5 project, but it doesn't mean you can use them with no errors*. So...
  • Use the facebook functionality only in OS 5.0 and above, by detecting it at runtime with DeviceInfo.getSoftwareVersion or DeviceInfo.getPlatformVersion.

Using this approach you might be able to have a single app compatible with 4.6+ devices, and only 5.0+ ones will use fb sdk.

*NOTE: I don't know why that facebook blackberry sdk is compiled for 5.0. Maybe the author just used the lower OS he had in his development machine, who knows. But without testing it I cannot state it is 4.5 compatible, just that the jar is 4.5 compilable.

Mister Smith
  • 24,695
  • 17
  • 97
  • 181
  • OK .. @Mister Smith: it means the JDE_4_7_0 is not used to detect OS – Yatin May 02 '12 at 09:23
  • Then how can 1 prepare just one build for 2 different OS ... ON HIGHER AND THE OTHER LOWER ...in THIS question the user wants to create one build for 4.6 and the other for 5.0 and above for faceboook package ... since the facebook package is not supported in 4.6 then how can it be used for both the OS @Mister Smith: – Yatin May 02 '12 at 09:25
  • 1
    In case you are talking about the unnoficial open source Facebook bb SDK, both jars (FacebookBlackBerrySDK-vx.x.x.jar and Log4B-vx.x.x.jar) are compilable with OS 4.5 despite the author used 5.0. But in general, to compile in "one build" you should use bbant tools, or else do it manually editing project properties. – Mister Smith May 02 '12 at 11:32
  • 1
    @Mister Smith are you sure that FB SDK is compilable with 4.5 net rim API (not 4.5 rapc)? It uses BrowserField2 which is available from 5.0 only – Eugen Martynov May 03 '12 at 11:22
  • 1
    @Eugen Martynov Is compilable because I've done it, what I'm not so sure is whether it would be usable without errors. – Mister Smith May 03 '12 at 12:08
  • 1
    @MisterSmith: is it possible to use one build for 2 different versions using bbant tools i mean i need facebook sdk support only on 5.0 and the other version is 4.6 which is unsupported are you really sure about it – Yatin May 04 '12 at 10:14
  • 2
    http://stackoverflow.com/questions/10445072/which-build-to-be-considered-for-use-when-a-preprocessor-is-used Please refer this question too where a similar question is raised where the comment by @HeartBeat says its not possible – Yatin May 04 '12 at 10:19
2

Change the directive name to something more like JDE_4_7_0_OR_HIGHER, then go into your project's Blackberry_App_Descriptor.xml file and add JDE_4_7_0_OR_HIGHER to the "Preprocess Directives" list, and then make sure it is enabled whenever you compile the project with a JRE version that is 4.7 or higher (you can install multiple JREs and then select a specific one in the project options before compiling). Then your code will look like this:

//#preprocess

//#ifdef JDE_4_7_0_OR_HIGHER
import net.rim.device.api.ui.component.ButtonField; 
//#else 
import net.rim.device.api.ui.component.LabelField; 
//#endif 
import net.rim.device.api.ui.container.MainScreen; 


public class TestScreen extends MainScreen{ 

        TestScreen(){ 

                //#ifdef JDE_4_7_0_OR_HIGHER
                ButtonField btn = new ButtonField("Test Button"); 
                add(btn); 
                //#else 
                LabelField lbl1 = new LabelField("Test Label 1"); 
                add(lbl1); 
                //#endif 
        } 
} 
Remy Lebeau
  • 454,445
  • 28
  • 366
  • 620