Upgrading the PhoneGap Library Used by the Android Hybrid Web Container

Sybase Unwired Platform comes with PhoneGap 1.4.1 libraries linked in; to upgrade to a later version of the PhoneGap library for use by the Hybrid Web Container, there are a few steps you must perform.

The PhoneGap library that is included with the Hybrid Web Container has been slightly modified to support title bars and loading URLs using binary.

  1. Download the PhoneGap package you are upgrading to from github.com.
  2. Open the DroidGap.java file for editing and under the onCreate method, comment out this line; doing so allows the screen to show the title bar:
    getWindow().requestFeature(Window.FEATURE_NO_TITLE)
  3. Replace the existing spinnerStop method with the following:
    public void spinnerStop() {
            if (this.spinnerDialog != null) {
                try
                {
                    this.spinnerDialog.dismiss();
                }
                catch( Exception e )
                {
                    // an exception occurs if the activity this dialog is associated with is closed
                    // before this dialog
                    LOG.d( TAG, "Tried to dismiss a dialog of an activity that no longer exists." );
                }
                finally
                {
                    this.spinnerDialog = null;
                }
            }
        }
  4. Add these methods to the DroidGap class:
    public void loadUrlWithData(String url, byte[] abData)
    {
      this.loadUrlIntoView(url, abData);
    }
    private void loadUrlIntoView(final String url) {
      loadUrlIntoView( url, null);
    }
    
  5. Modify the original private void loadUrlIntoView(final String url) method so that the signature accepts binary data.
    private void loadUrlIntoView(final String url, final byte[] abData)
  6. At the bottom of the private void loadUrlIntoView(final String url) method, change the line me.appView.loadUrl(url); to:
    if ( abData == null)
      me.appView.loadUrl(url);
    else
      me.appView.loadDataWithBaseURL( url, new String( abData ), null, "utf-8", null );
    
  7. Open the CordovaWebViewClient.java file and, at line 137, add:
    if ( url.indexOf(this.ctx.baseUrl) == 0 ) { return false; }
    This step is a workaround for a problem PhoneGap 1.4.1 has when loading a local file into an Iframe; it opens in the main window instead. See https://issues.apache.org/jira/browse/CB-132.
  8. Use Apache Ant to build PhoneGap, run the following command from the PhoneGap framework directory:
    1. In the parent directory of the PhoneGap framework directory, create a file named "VERSION" (no extension).
    2. Edit this file with a text editor and enter the version number (this is the value that is used when naming the .jar file).
      For example, if you have "1.5.0" in the VERSION file, the jar is named cordova-1.5.0.jar.
    3. Create a file named "local.properties" in the PoneGap framework directory.
    4. Edit this file with a text editor and enter:
      "sdk.dir=C:\\Program Files\\android-sdk-windows"
      Ensure the filepath is the correct filepath to your Android installation directory.
    5. From the PhoneGap framework directory, execute:
      ant.bat –f build.xml
    If you do not have Apache Ant installed, you can download it from http://ant.apache.org/bindownload.cgi.
  9. Put the resulting cordova-<version>.jar file in the HybridWebContainer\libs folder of the project and delete the old phonegap-<oldversion>.jar file from the folder.
  10. In the Java perspective in Eclipse, right-click the HybridWebContainer project and choose Properties.
  11. Go to the Java Build Path section, and click the Libraries tab.
  12. Select the old phonegap<version>.jar file and click Remove.
  13. Add the new cordova-<version>.jar file.
  14. Open the UiHybridAppContainer.java file and update the Hybrid Web Container template code by changing import com.phonegap.DroidGap to import org.apache.cordova.DroidGap.
  15. Open the plugins.xml file, which is located in HybridWebContainer\res\xml\, for editing and change all references of com.phonegap to org.apache.cordova
    For example, change com.phonegap.App to org.apache.cordova.App.
    These steps complete the upgrade to the new version of PhoneGap. Some additional steps are required to upgrade the Mobile Workflow Forms Editor to use the new version of PhoneGap so that new Mobile Workflow applications reference the correct version of PhoneGap.
  16. Navigate to <UnwiredPlatform_InstallDir>\UnwiredPlatform\Unwired_WorkSpace\Eclipse\sybase_workspace\mobile\eclipse\plugins.
  17. Use WinZip to open com.sybase.uep.xbw.generatewizard_2.1.3.201202161213.jar.
  18. Replace the generate\html\js\android\phonegap-1.4.1.javascript file with the JavaScript file framework\assets\www\cordova-<version>.javascript.
    Note: The extension must be .javascript, not .js. If necessary, modify the extension to .javascript.

    To change the PhoneGap version for other platforms as well, replace the phonegap-1.4.1.javascript for each platform, for example, for iOS, replace \html\js\ios\phonegap-1.4.1.javascript.

  19. For each Workflow application that is using the new version of PhoneGap, open the Generated Workflow\<workflow_name>\html\js\API.js file for editing.
  20. Locate the loadPhoneGap() function at the bottom of the file and change the line jsfile = pre + "js/android/phonegap-1.4.1.javascript"; to jsfile = pre + "js/android/cordova-<version>.javascript";, where <version> is the new version of PhoneGap.
    Note: You must modify the same line for each platform if you want other platforms to use the new version of PhoneGap, for example, for iOS: jsfile = pre + "js/ios/phonegap-1.4.1.javascript";.