Why KeyCodeNumber exception after signing Blackberry app? - blackberry

We've signed a 4.7 Blackberry application with the 4.6 code-signing tool. But when starting the application a second time it throws a 'KeyCodeNumber exception'.
Anybody some clues to why we get this exception?
Thanks!

KeyCodeNumber exceptions have todo with the verification process.
Blackberry published an article describing how to prevent verification errors:
When developing Java applications for
the BlackBerry smartphone, you may
encounter any of the following
verification errors or errors similar
to the following:
Verification Error 3141 Module
'MyMIDlet' has verification error
(<###>) at offset <###>. Error
starting MyMIDlet: Module 'MyMIDlet'
has verification error (<####>) at
offset <###>." These errors often
occur when creating MIDlets. They are
inherently hard to debug because the
same error message can apply to a
number of problems.
The following is a list of possible solutions to prevent or correct verification errors:
If you started by building a Java
Archive (JAR) file and then used the
RIM Application Program Compiler
(RAPC) to create .cod files, make
sure you turn obfuscation off when
building the JAR file. The RAPC
compiler performs its own
obfuscation and issues may occur if
the code is already obfuscated.
Remove any System.out.* calls. These
generally do nothing on the
BlackBerry smartphone, but they
might cause verification errors.
Remove unused import statements.
Explicitly specify the access for
each function or variable. For
example, make sure each one is
specified as public, private, or
protected.
If you are working with a MIDlet,
make sure the MIDlet class is
declared as public.
Verification errors may occur if the
COD file is corrupted or if it was
not signed correctly. Make sure that
you perform a clean rebuild and that
you re-sign your application.
Reinstall the application on the
BlackBerry smartphone.
Comment out any non-executable code.
Verification errors might be related
to the size of the main code file
and the library files. If you
comment out non-executable code, the
file sizes change, which may correct
the problem.
If you have created any classes that
inherit from RIM classes, change the
name of any custom methods and
members that you created in those
classes. This makes sure that you
have not named any methods or
members of the same name in the
internal RIM classes.
If your application is using
BlackBerry® Device Software 3.8 or
later, verification errors occur
when an application that implements
the
javax.microedition.rms.RecordStore
class is compiled using BlackBerry®
Java® Development Environment
(BlackBerry JDE) earlier than
version 4.0. This occurs if the
application uses either the
addRecordListener or
removeRecordListener methods of the
RecordStore class. To resolve this
issue, recompile the application
using BlackBerry JDE 4.0 or later.
There is a problem with how the
BlackBerry® Java® Virtual Machine
(BlackBerry JVM) handles the
referencing of a class directly
within the constructor of another
class. The following is an example:
Class1 class1= new
Class1(Class2.class.getName());
To work around this issue, do not make the class call within a constructor as shown in the following example:
Class1 class1;
String className = Class2.class.getName();
Class1 = new Class1(className);
Remove references to a static instance variable from an inner class. For example, the following code example could cause an error:
public class MyOuterClass {
static int var;
class MyInnerClass {
public void doSomething() {
var = 7;
}
}
}
There are a few ways you can remove these references, such as creating get/set methods for var in the outer class or modifying the logic to pull MyInnerClass out of MyOuterClass.
The build procedure normally
compiles from the java source file
with the javac command, and then
runs preverify.exe file and then
RAPC. Add the following command line
arguments to javac to help avoid
issues in earlier versions of the
RAPC:
javac.exe -source 1.3 -target 1.1
Some methods that are very long can
cause verification errors. By
breaking these methods into helper
methods, you can reduce the
likelihood of verification errors.
Although not as likely, some very
long method definitions (with 10 or
more parameters), and some very long
constant definitions (long package
structure and/or long names) can
also cause verification errors.

Related

How to use PathCchCanonicalizeEx with C++Builder 10.2?

I have a legacy Windows project using the legacy 32 Bit C++ compiler. For various reasons I need to use the Windows 8+ function PathCchCanonicalizeEx. C++Builder seems to provide the header and some module definition file for that, but I can't find any library to link against:
[ilink32 Error] Error: Unresolved external 'PathCchCanonicalizeEx' referenced from C:\[...]\WIN32\DEBUG\TMP\FILE.OBJ
How am I supposed to fix this? Do I need to add a Windows 8.1 SDK? Is the necessary lib simply named differently and I can't find it? Something completely different?
According my tests, one has two options:
IMPLIB/MKEXP
I'm developing/testing a some Windows 10 21H2, which provides an implementation for PathCchCanonicalizeEx in some DLL already. So if that source DLL is known, one can use IMPLIB or MKEXP to create an import library manually. I did that and after adding the created library from IMPLIB to my project, the linker errors were instantly gone.
Though, it's not that easy to know where PathCchCanonicalizeEx is placed in. One pretty easily finds the api-ms-win-core-path-l1-1-0.dll, but that thing is NOT an actual file on the disk and therefore can't be used by IMPLIB or MKEXP. That name is only a virtual concept for the library loader to address the same named API set of modern Windows, the extension .dll doesn't mean it's a file at all.
You can use an API set name in the context of a loader operation such as LoadLibrary or P/Invoke instead of a DLL module name to ensure a correct route to the implementation no matter where the API is actually implemented on the current device. However, when you do this you must append the string .dll at the end of the contract name. This is a requirement of the loader to function properly, and is not considered actually a part of the contract name. Although contract names appear similar to DLL names in this context, they are fundamentally different from DLL module names and do not directly refer to a file on disk.
https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-apisets#api-set-contract-names
What you really need to work with is KernelBase.dll, which is even documented by MS.
implib "KernelBase x86.lib" C:\Windows\SysWOW64\KernelBase.dll
implib "KernelBase x86-64.lib" C:\Windows\System32\KernelBase.dll
Module Definition File
The downside of manually creating LIB files is that one needs to maintain those with the project. Things depend on if the target is 32 or 64 Bit, DEBUG or RELEASE, so paths might become a bit complex, one might need to create relative paths for libraries in the project settings using placeholders for the target and stuff like that.
It seems that all of this can be avoided with Module Definition Files, which's purpose is to provide IMPORT and EXPORT statements to either consume exported functions by other DLLs or make that possible for others with own functions. I've successfully resolved my linker problems by simply creating a file named like my app using the extension .def alongside my other project files. That file needs to be added to the project, though.
dbxml.cbproj
dbxml.cbproj.local
dbxml.cpp
dbxml.def
dbxml.res
[...]
The following content made the app use the correct function from the correct DLL. Though, what didn't work was using the API set name, which resulted in an error message by the linker.
IMPORTS
KernelBase.PathCchCanonicalizeEx
IMPORTS
api-ms-win-core-path-l1-1-0.PathCchCanonicalizeEx
[ilink32 Error] Invalid command line switch for "ilink32". Parameter "ItemSpec" cannot be null.
[ilink32 Error] Fatal: Error processing .DEF file
The latter is after restarting C++Builder, so I guess the format of the file is simply wrong because of the API set name.

Blackberry 7 - releasing SDK to multiple apps causes issues

Below issues have been discussed in isolation but I could not find a solution which works. Hence posting the complete story and list of issues.
We are building an SDK(midlet jar) to be consumed by multiple apps. This SDK uses persistent store to store certain data. Now couple of issues plaguing us:
1. The key to access the store has been hard-coded in the SDK. Now multiple apps try to access the store with same key value resulting in conflicting issues.
2. The Persistable object package/class name is the same in multiple apps. Because of this we get the "Class Multiply defined" error while launching the apps.
Now for 2, we have been mulling over below options but none of them seem to solve the issue:
1. Do not extend the standard objects like Vector and use standard objects.
Issue: recycling of data is lost causing conflicts.
2. Build the library with a unique name for each application that uses it.
Issues: This would mean we will have to release a different SDK for every client who wants to use it.
3. Check if the Persistable object class already exists before loading the package for the next app.
Issues: What happens when the first package is unistalled? the class type would be deleted?
4. Ask the app to implement the Persistable interface and also pass the key in a callback.
This does not sound right to ask the app to pass some values just because we are not able to use the persistent store.
So as of now SDKs using Persistable objects seems to be totally broken. Or are we missing something?
Any other alternative suggestion to achieve the task is also very welcome.
if there is a library which functionality can be shared among different applications then make it as a library cod file, and specify this cod file as a library upon compiling the dependent projects.
For instance, if the library name is mylib_version1_00.cod then your other projects could contain the following files after compilation:
for Project1:
project1.cod
mylib_version1_00.cod
for Project2:
project2.cod
mylib_version1_00.cod
......
for for ProjectN:
projectN.cod
mylib_version1_00.cod
upon installation of every project you will install mylib.cod file, and if there's already installed mylib.cod file it will be overwritten, and it will avoid "class xxx multiply defined".
This error occurs because all applications are running under one JVM instance. So if you are uploading to device a cod file with the name, that already exists, it will be rewritten.
In case you will release the next version of your library, name the cod file as
mylib_version2_00.cod
and use version number in package name, for instance:
com.yourcompany.yourpoduct.yourlibary.version1
com.yourcompany.yourpoduct.yourlibary.version2
In this case you can have on the same device cod files: mylib_version1_00.cod and mylib_version2_00.cod and it won't produce "class xxx multiply defined" error.
Now about the persistence. Do not hardcode persistence key in your library. Make an abstract class and declare an abstract method like:
public long getPersistenceKey();
which returns a unique persistence key for an object. And use this method call in the code that persists the information in your abstract class.
and in children classes, used in your custom applications just override this method with different values for every product. And there won't be confilcts anymore.
Hope this helps.
There can be only one persistable class with a given classname on the entire device. If two apps have the same class which are persistable, you'll get a Class Multiply Defined verification error and the second app will not install at all.
The only way is to use the builtin persistable classes for storing persistable data in the SDK. However, this persitable data will not be deleted even when all the apps containing the SDK have been removed by the user. You will also have to take care of the versions of the data to be backward compatible.
You store the data using a builtin class like Hashtable, IntHashtable or Vector. Then you write a wrapper class which gets and sets this information. Basically you'll be mapping your persistable class to a Hashtable or Vector.
Again remember, you should never put any class that is not builtin into this datastore. Otherwise, the datastore will get deleted on the app uninstall.
Hope that helps.

Exceptions in my iOS Framework Show Private Code?

I'm building an iOS framework where only a single header file is exposed, and the rest of the code is private. Within Xcode I have all objective-c exception breakpoints on, so normally when there's an exception I'm brought to where it occurred in the code.
During testing in a totally new project that is using this framework I created, every now and then when an exception is raised inside the framework, I'm brought to the otherwise private framework code, which is obviously not what I want.
I think this may be because the actual raw framework code/project exists in my environment and wouldn't occur for another person using my framework without access to the actual files, but unfortunately I don't have any way to currently test this theory. Does anyone know if this is something I need to be handling in order to truly keep the project files private that I intent to, or is this just a function of having the code exist locally?
I was able to get in another dev environment with a fresh project to drop in the framework and force an internal framework crash and it appears that if the otherwise private framework files exist on the same environment and a crash occurs when you have objective-c exception breakpoints enabled it will open the private framework file in question, BUT if you don't have those private framework files (which consumers of your framework wouldn't) you will simply be taken to the normal crash/stack trace view like below:

How to resolve "Main module of program is empty: nothing will happen when it is run"

I have two projects in an F# solution.
1. main project with [EntryPoint] and set as the StarUp project.
2. support, the second project, holds a group of support modules. I.e. they are only called and never initiate anything nor serve as the entry point nor are the StartUp project.
For the last module in the support project, compiling in Visual Studio gives
warning FS0988: Main module of program is empty; nothing will happen
when it is run
While using compiler option nowarn inline as #nowarn "988" in the module causing the warning does suppress the message I would rather add something like a dummy function with comments that resolves the issue.
How does one make such a dummy function to resolve the warning?
EDIT
Jack is correct in that my support project was setup as a Console Application instead of a Class Library. Changing to Class Library resolved the warning. It is also nice to know about do () for the other case.
EDIT
While it seemed odd that I would have set a support project as a Console Application, I recently found that for some reason when I made a change to the code in the project, something changed the Output type from Class Library to Console Application. I suspect it has to do with the F# PowerPack and it's build rules, but it's only a guess.
Are you building the support project as a Library or as a Console Application? (This is set via the project properties page.)
If you're building it as a library, then you may need to add a do() at the end of the last file in the project. This is necessary to make the F# compiler happy in a few specific scenarios, like when you create a module which contains only assembly-level attributes (because they're applied to the assembly, the module appears "empty" to the compiler).
You can see an example in my code here:
https://github.com/jack-pappas/FSharp.Compatibility/blob/master/FSharp.Compatibility.OCaml/AssemblyInfo.fs

Error Starting xxx: Module 'xxx-4' has verification error 3337. (Codfile version 78) in Blackberry?

I've implemented a blackberry application using JRE5.0, it's running well on any device with OS5.0 and OS6.0
When I try to open the same application on 9900 which has OS 7.0, I got the following error:
Error Starting myAppName: Module 'MyAppName-4' has verification error
3337. (Codfile version 78)
where myAppName is the application name (name of the cod file)
as in the following image:
I checked the event logger, here what it contains (older to newer):
a System - VM:LINK MyAppName
a System - VM:VECPs=my.Package.Name.Containing.Screens
a System - VM:VECCs=oneOfMyScreenClassNames
a System - VM:VECMm=functionInOneOfMyClasses()
Module 'MyAppName-4' has verification error 3337 (codfile version 78)
Linker error: 'VerifyError' for MyAppName
Error starting myAppName: Module 'MyAppName-4' has verification error 3337 (codfile version 78)
Here is the content:
E System - JVM:INFOp=2100000a,a='7.0.0.296',o='4.0.0.127',h=7001204
For those who are interested, I found the solution.
In the logs there were:
a System - VM:VECCs=oneOfMyScreenClassNames
a System - VM:VECMm=functionInOneOfMyClasses()
I did the next steps in the whole class "oneOfMyScreenClassNames" indicated in logs
Here are the steps:
If you started by building a Java Archive (JAR) file and then used the RIM Application Program Compiler (RAPC) to create .cod files, make sure you turn obfuscation off when building the JAR file. The RAPC compiler performs its own obfuscation and issues may occur if the code is already obfuscated.
Remove any System.out.* calls. These generally do nothing on the BlackBerry smartphone, but they might cause verification errors.
Remove unused import statements.
Explicitly specify the access for each function or variable. For example, make sure each one is specified as public, private, or protected.
If you are working with a MIDlet, make sure the MIDlet class is declared as public.
Verification errors may occur if the COD file is corrupted or if it was not signed correctly. Make sure that you perform a clean rebuild and that you re-sign your application. Reinstall the application on the BlackBerry smartphone.
Comment out any non-executable code. Verification errors might be related to the size of the main code file and the library files. If you comment out non-executable code, the file sizes change, which may correct the problem.
If you have created any classes that inherit from RIM classes, change the name of any custom methods and members that you created in those classes. This makes sure that you have not named any methods or members of the same name in the internal RIM classes.
If your application is using BlackBerry® Device Software 3.8 or later, verification errors occur when an application that implements the javax.microedition.rms.RecordStore class is compiled using BlackBerry® Java® Development Environment (BlackBerry JDE) earlier than version 4.0. This occurs if the application uses either the addRecordListener or removeRecordListener methods of the RecordStore class. To resolve this issue, recompile the application using BlackBerry JDE 4.0 or later.
There is a problem with how the BlackBerry® Java® Virtual Machine (BlackBerry JVM) handles the referencing of a class directly within the constructor of another class. The following is an example:
Class1 class1= new Class1(Class2.class.getName()); To work around this issue, do not make the class call within a constructor
Remove references to a static instance variable from an inner class. There are a few ways you can remove these references, such as creating get/set methods for var in the outer class or modifying the logic to pull MyInnerClass out of MyOuterClass.
The build procedure normally compiles from the java source file with the javac command, and then runs preverify.exe file and then RAPC. Add the following command line arguments to javac to help avoid issues in earlier versions of the RAPC:
javac.exe -source 1.3 -target 1.1
Some methods that are very long can cause verification errors. By breaking these methods into helper methods, you can reduce the likelihood of verification errors.
Although not as likely, some very long method definitions (with 10 or more parameters), and some very long constant definitions (long package structure and/or long names) can also cause verification errors.
Source: http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/Support_-_Preventing_verification_errors.html?nodeid=1499031&vernum=0
PS, I also removed "instanceOf" usage in code

Resources