Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlackBerry - use own JAR file in own project

(I have solved my problem, so have edited it to look more like a blog post - the final working solution has been placed as an "answer" below.)

Aim

I want to package our BB libraries (v4.5 OR v5.0) into JAR format, so we can give application source code to clients WITHOUT giving library source code.

Workaround

Currently, I have my SDK, and my apps, all setup with source code, as different projects in the same workspace. All projects compile. My SDK is setup as a library project, my apps as applications.

In each app, I add the SDK project to the build path.

Eclipse handles the build perfectly, creates the various COD files. I copy & unzip the COD files into the same folder, run updatejad to combine the JAD files, and end up with many COD files that install perfectly.

Problem is - the library is required to be in source code.

Problems Encountered

There are many conflicting sources of information on this. The process is simple, but not well documented. In some attempts, I have encountered the following problems:

  1. JAR file needing preverification (perhaps a topic for another comprehensive post in the future)
  2. JAR file needing the RIMAPPSA2 "secret" signature from the signing tool
  3. Final built app being seen as "not signed" despite signing tool confirming success
  4. Final built app not finding the SDK code (JAR file was not exported in the build path settings)

Unfortunately the main document that seems to be referenced from RIM is incorrect - details below.


(I hope its OK to cross-reference this question with the following long list of links?)

StackOverflow links:

  • Blackberry: Verificattion error when using Library project as External Jar
  • https://stackoverflow.com/questions/6134940/how-to-use-external-library-jar-file-in-blackberry
  • Blackberry 5.0 - Add reference to a Java Library Project
  • How to add external jar or zip file in the Blackberry project
  • Blackberry Apps - Importing a code-signed jar into an application project
  • How to add library project with the current development project in blackberry

This one gives other links - quite useful:

  • Handling dependencies in blackberry development

These not so useful:

  • In Blackberry, can we create common library that can be used by different applications?
  • BlackBerry Facebook SDK jar file
  • Adding and Testing Compatibility of External Jar to Blackberry Project
  • How to attach Jar in Blackberry
  • BlackBerry RIMAPPSA2 signing key required -- why?
  • Is there a list of classes, methods and API which will trigger RIMAPPSA2 permission when signing Blackberry application?

RIM:

  • http://docs.blackberry.com/en/developers/deliverables/12002/Add_jar_dependency_923677_11.jsp
like image 373
Richard Le Mesurier Avatar asked Apr 02 '12 12:04

Richard Le Mesurier


People also ask

How to install JAR file in BlackBerry?

How to install JAR file in Blackberry? Open My Computer and open your media card memory disk, usually labeled as Removable and Paste the JAR file In your smart phone go to Media → Explore and locate the JAR file you have just copied from your computer Click on the *.

How to install Java apps on BlackBerry devices?

But there are java apps specifically written for Blackberry devices. These will install without any hiccup. Here is how to install a jar file: Copy the jar file to the memory card. In the BB, open the file manager. Browse to where you saved the jar file and click it. Now click ‘Download’.

What file types can be used to install applications on BlackBerry?

You can install three types of files: .jar, .jad and .cod . Let’s look at how to install applications in these formats: .JAR or Java applications: Blackberry has limited support for .jar files. It may or may not install on your BB. Because Blackberry do not support some of the modules required by some .apps.

How do I open a JAR file on my smart phone?

Open My Computer and open your media card memory disk, usually labeled as Removable and Paste the JAR file In your smart phone go to Media → Explore and locate the JAR file you have just copied from your computer


1 Answers

I have managed to solve the problem so have edited the question, and placed the final procedure, with notes, down here:

1) Change the SDK project to be a MIDLET application as per this link (Richard Schilling’s Professional Weblog)

  • The BlackBerry support forum has a post (Working with Libraries) erroneously advises the developer to set the project to be an APPLICATION.
  • If you follow those instructions, you may get a signing error requiring the infamous RIMAPPSA2 signature which we are not allowed to sign.

2) Build the SDK project in Eclipse. Package & Sign the project as normal.

  • This will create a JAR file in the deliverables folder (....deliverables\Standard\5.0.0)

3) Copy that resulting JAR file into your project, and update the build path to use that JAR.

  • You could probably get working results by just adding it as an external JAR, but I prefer to store the JAR files with my projects for now.

4) Also in the build path settings, go to the "Order & Export" tab & check the box to export this JAR file.

WARNING: at this point a lot of users seem to encounter the bug where Eclipse tells you "Project {0} has to have a jad file file if it exports a mildlet jar". This error happens if you do not set the SDK project's type to MIDLET.

  • If you get this error, please check the project's build type.

  • If you have set it to MIDLET correctly, try editing the manifest inside the JAR file, to remove the line MicroEdition-Profile- MIDP-2.0.

  • Full details are given in this link: "Project {0} has to have a jad file file if it exports a mildlet jar" error appears in BlackBerry Java Plug-in for Eclipse

NOTE: regarding the RIMAPPSA2 signature, I found some info about getting rid of that requirement. The steps seem strange, but they worked for me insofar as the signing stage went. Unfortunately for me the app didn't run on the phone (still requiring some signatures). But these steps might help someone else & can be found at Frustrations with Blackberry Developer plugins for Eclipse

NOTE 2: remember to refresh your project after reimporting a new build of the JAR file, if you have to go back to step 1 (otherwise Eclipse will keep using the old one you have just overwritten).


So to summarise:

  1. Build the SDK as a MIDLET.
  2. Package & Sign the SDK.
  3. Import into application project & be sure to check the box to export it in the build path settings.

If you get questions about RIMAPPSA2 signatures, see step 1.

Easy when you know how - but this took me many days to get right?!?

like image 167
Richard Le Mesurier Avatar answered Sep 29 '22 06:09

Richard Le Mesurier