Saturday, March 27, 2010

Java OTA download error messages

In Java ME the success or failure of an OTA download attempt is reported by means of installation status reports. These status reports are posted to the server using the URL specified in the following JAD attributes: MIDlet-Install-Notify  for installations and MIDlet-Delete-Notify for deletions. Otherwise when the application installation fails it just displays the status code and a rather cryptic error message. I am going to document what I know about these errors.

900: Success: This means that the app has been successfully installed.

901: Insufficient Memory: If there is insufficient memory to store the app on the device, it returns this error.

902: User Canceled: It is returned when the user cancels the application download.

903: Loss of service: This status code is returned if the installation failed due to a network failure. Note that usually nothing is sent to server as the network connectivity itself is not available.

904: JAR size mismatch: If the downloaded application JAR file size does not match the size specified in the JAD file, this error is returned.

905: Attribute Mismatch: This error indicates that there is a mismatch between the JAD file attributes and those in the JAR file's manifest. The JAD file attributes (both key and value) that are in manifest file in JAR should match exactly.

906: Invalid Descriptor: The following attributes are mandatory and should be present in all JAD files.
  1. MIDlet-Name
  2. MIDlet-Version
  3. MIDlet-Vendor
  4. MIDlet-Jar-URL
  5. MIDlet-Jar-Size
And if any of these attributes are also in JAR file's manifest, then they will have to match exactly or else you will get this error.

In some cases, we need to specify MIDlet-Data-Size attribute in JAD and manifest files. This attribute will determine the amount of RMS allocated for the app. If you specify too much then the installation may be denied. Usually for apps not using RMS this attribute is not defined in JAD or manifest files. And other times when this error crops up, setting this attribute (with a 1024 size) fixes it.

907: Invalid JAR:  This is a server error. It occurs when the one of the following HTTP errors happen: 400, 402, 404, 405, 406, 408 etc. Mime type setting on server may be one possible cause. One other cause is the JAR file specified in MIDlet-Jar-URL line is not available for download.

For BlackBerry handsets sometimes we get this error: "907 invalid COD. Unable to import ZIP file". This is because someone was trying to download the COD files that were still zipped up. The JAR file should be unzipped and then the app should be downloaded.

908: Incompatible configuration or profile: Sometimes the error string will be "Application has malformed attribute". There may be a few possible causes like, the required JAD attributes in JAD file may be wrong. There may be a typo in the JAD file.

909: Application authentication failure: This is mostly caused because the application was signed incorrectly, or the signature did not match the certificate on handset.

910: Application authorization failure: This error happens when we are trying to replace a signed app on the handset with an unsigned one. It is especially noticable for preload handset which have apps baked in with the firmware. Its a common developer mistake to try to download a unsigned app on the preload handset, which has a signed version on it already.

911: Push registration failure: Dont know much about this error, but I think it is not supported anymore.

912: Deletion Notification: This error is displayed when we try to delete the app on the handset and the delete attempt fails. It usually happens for apps that were preloaded and thus cant be deleted. However, if we have a later version of the same app with correct signing then the older version can be overwritten.

Thursday, March 18, 2010

Android Error: Conversion to Dalvik format failed with error 1

I wanted to document something that I learnt about Android development, particularly, this error:

Conversion to Dalvik format failed with error 1

It can happen typically when someone starts their Android project in Eclipse. The project can be as simple as a "Hello World" project, this error may still come up. Apparently Eclipse does some internal caching for ADT (version doesn't seem to matter, I have seen it from 0.8.0 version to 0.9.6 version) and when we update Android Tools in Eclipse, it gets corrupted. Here is what I tried and worked for me. My installation is Eclipse 3.5.1 and ADT 0.9.6.

Option One:
In Eclipse, delete your project (back up the source before, of course). Restart Eclipse, recreate the project and the error will go away. This worked for some, but it didn't for me.

Option Two:

Next is to delete your project, start Eclipse on command line with clean option:

eclipse -clean

This cleans up any cached data that Eclipse stores. Now recreate your project and hopefully the error is gone. Well, sometimes it doesn't work. On to the next option.

Option Three:
Delete your project. Uninstall all Android plug-ins in Eclipse and restart it with clean option. Now install your required Android plug-ins.
    Create your project, hopefully the error is gone, if not continue reading. In your project home, eclipse will create a .classpath file. Open it in an editor, and ensure that each of the following lines exist in it.

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry kind="src" path="gen"/>
        <classpathentry kind="output" path="bin"/>
    </classpath>


    Note that there will be other lines relevant to your project like


    <classpathentry combineaccessrules="false" kind="src" path="/project-name"/>

    that is okay, the key thing is this line is:

    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>


    It needs to be in there. Make this change and save the file, and restart Eclipse. In main menu, do Project -> Clean. Now in project explorer, on the new project you just created, Right Click -> Properties -> Android -> Check Android 1.5 -> Click Apply Button.

    Next project, Right Click -> Properties. In the menu on left, click on Java Build Path, on right panel, click on Libraries tab. Ensure that you see a folder called "Android 1.5". Now hit OK and your project should compile.

    In the Library tab, if you see Android.jar then it must be deleted manually (highlight and click "Remove" button) and then this error will be gone.

    Apart from this I have heard one other option to try to remove this error. I didn't try it but it is supposed to work. First delete Android.jar from right click on Project -> Properties ->Java Build Path -> Libraries tab. Then Right Click the Project -> Android Tools -> Fix Project Properties. This will add Android 1.5 folder and this error will be gone.

    I haven't tested this with other versions of Andriod SDKs but I don't see why they wont work.