MobileFirst Developer
MobileFirst Developer

Reputation: 109

MobileFirst 7.1 - Issue with JSONStore Hybrid App when deployed on Android

I am trying to use JSONStore for one of the requirement.

And as it is hybrid app I configured it by following Procedure

Using the Application Descriptor Editor, open the file application-descriptor.xml Click the Design tab. Under Overview, expand Application [your application's name]. Click Optional Features. Click Add. Select JSONStore. Click Ok. In the Project Explorer view, right-click the folder that is titled with your application name. Click Run As. Click Run on MobileFirst Development Server.

Here is the sample code I use to create the document in JSONStore. I followed the instruction given in this documentation.

WL.Logger.debug ("Successfully connected to MobileFirst Server.");

    var collectionName = 'SomeFlag';

    if(WL.JSONStore.get(collectionName) == null && WL.JSONStore.get(collectionName) == undefined){      
        // Object that defines all the collections.
        var collections = {

          // Object that defines the 'people' collection.
                userAgreement : {

            // Object that defines the Search Fields for the 'people' collection.
            searchFields : {someFlag: 'boolean'}
          }
        };

        // Optional options object.
        var options = {
          localKeyGen : false
        };

        WL.JSONStore.init(collections, options)

        .then(function () {
          var data = [{someFlag: false}];

          // Optional options for add.
          var addOptions = {

            // Mark data as dirty (true = yes, false = no), default true.
            markDirty: true
          };

          // Get an accessor to the people collection and add data.
          return WL.JSONStore.get(collectionName).add(data, addOptions);
        })

        .then(function (numberOfDocumentsAdded) {
            WL.Logger.debug ("Number Of Documents Added " +numberOfDocumentsAdded);
            alert ("Number Of Documents Added " +numberOfDocumentsAdded);
          // Add was successful.
        })

        .fail(function (errorObject) {
           // Handle failure for any of the previous JSONStore operations (init, add).
            WL.Logger.debug ("JSONStore Failed to add any document errorObject " +errorObject);
        });
    }

When running in Android the JSONStore creation fails.

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/worklight/jsonstore/util/JSONStoreUtil;
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.jsonstore.dispatchers.BaseActionDispatcher.<init>(BaseActionDispatcher.java:44)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.jsonstore.dispatchers.BaseDatabaseActionDispatcher.<init>(BaseDatabaseActionDispatcher.java:29)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.jsonstore.dispatchers.AllDirtyActionDispatcher.<init>(AllDirtyActionDispatcher.java:36)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at com.worklight.androidgap.plugin.StoragePlugin.initialize(StoragePlugin.java:59)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:50)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:195)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.PluginManager.exec(PluginManager.java:141)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:61)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:40)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:37)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at android.os.Looper.loop(Looper.java:135)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:61)
    01-08 13:34:03.962 12289-12425/com.DCSSMobileApp W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.worklight.jsonstore.util.JSONStoreUtil" on path: DexPathList[[zip file "/data/app/com.DCSSMobileApp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.DCSSMobileApp-2/lib/arm, /vendor/lib, /system/lib]]
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:  ... 14 more
    01-08 13:34:03.964 12289-12425/com.DCSSMobileApp W/System.err:  Suppressed: java.lang.ClassNotFoundException: com.worklight.jsonstore.util.JSONStoreUtil
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.Class.classForName(Native Method)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:      ... 15 more
    01-08 13:34:03.965 12289-12425/com.DCSSMobileApp W/System.err:  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Upvotes: 0

Views: 321

Answers (2)

MobileFirst Developer
MobileFirst Developer

Reputation: 109

Finally got it working. I found that jsonstore.jar was not included in my Android project lib which caused this error.

Upvotes: 0

Idan Adar
Idan Adar

Reputation: 44516

I am using the same build as mentioned in the comments and was able to successfully run JSONStore w/out encountering this error.

  1. Create a new Hybrid app and added the Android environment
  2. Added the JSONStore optional feature
  3. Added the following code in common/js/main.js > wlCommonInit():

    function wlCommonInit(){
        var collectionName = 'people';
    
        // Object that defines all the collections.
        var collections = {
            // Object that defines the 'people' collection.
            people : {
                // Object that defines the Search Fields for the 'people' collection.
               searchFields : {name: 'string', age: 'integer'}
            }
        };
    
        // Optional options object.
        var options = {
            // Optional username, default 'jsonstore'.
            username : 'carlos',
    
            // Optional password, default no password.
            password : '123',
    
            // Optional local key generation flag, default false.
            localKeyGen : false
        };
    
        WL.JSONStore.init(collections, options)
    
        .then(function () {
            alert ("success");
        });
    }
    

I launched the application in the Android Emulator and the alert displayed.

Upvotes: 0

Related Questions