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.
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.
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
}
}