function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
agusagus 

AngularJS and Hybrid Android app with SmartStore support

Hello everybody,

 

I was trying to get a Hybrid app up and running, using AngularJS and SmartStore, but I just can't seem to get it to work, I tried importing the www folder from the angularJS cordova bootstrap example in AngularJS repo, replacing Cordova and force javascript files in that folder with the Android ones, and the pasting that folder on the newly created hybrid app (the one created with forceDroid).
The application starts with no problem if I manage it only online, but when I import the SmartStore library, it stops working, this is a very strong requirement for my project, so I need to make it work.
I appreciate any help from someone who could make AngularJS and SmartStore work toghether, thanks in advance.

Agustín Gallardo.

 

Here's a console LOG, if it helps in any way.

08-26 12:57:30.181: D/HttpAccess:constructor(329): User-Agent string: SalesforceMobileSDK/2.0.3 android mobile/2.3.3 (sdk) hybridTestingAngularJS/1.0 Hybrid
08-26 12:57:30.290: I/SalesforceDroidGapActivity.onCreate(329): onCreate called
08-26 12:57:30.494: I/SalesforceDroidGapActivity.onResumeLoggedInNotLoaded(329): Local start page - loading web app
08-26 12:57:30.500: I/SalesforceDroidGapActivity.loadLocalStartPage(329): loading: index.html
08-26 12:57:30.530: I/dalvikvm(329): Could not find method android.webkit.WebView.<init>, referenced from method org.apache.cordova.CordovaWebView.<init>
08-26 12:57:30.530: W/dalvikvm(329): VFY: unable to resolve direct method 584: Landroid/webkit/WebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
08-26 12:57:30.530: D/dalvikvm(329): VFY: replacing opcode 0x70 at 0x0001
08-26 12:57:30.530: D/dalvikvm(329): VFY: dead code 0x0004-005b in Lorg/apache/cordova/CordovaWebView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;IZ)V
08-26 12:57:30.690: I/CordovaLog(329): Changing log level to DEBUG(3)
08-26 12:57:30.690: I/CordovaLog(329): Found preference for classicRender=true
08-26 12:57:30.700: D/CordovaLog(329): Found preference for classicRender=true
08-26 12:57:30.730: D/JsMessageQueue(329): Set native->JS mode to 2
08-26 12:57:30.730: I/CordovaWebView(329): Disabled addJavascriptInterface() bridge callback due to a bug on the 2.3 emulator
08-26 12:57:30.730: I/SalesforceDroidGapActivity.init(329): init called
08-26 12:57:30.739: D/DroidGap(329): DroidGap.init()
08-26 12:57:30.769: D/CordovaWebView(329): >>> loadUrl(file:///android_asset/www/index.html)
08-26 12:57:30.769: D/PluginManager(329): init()
08-26 12:57:30.789: D/CordovaWebView(329): >>> loadUrlNow()
08-26 12:57:30.799: D/SoftKeyboardDetect(329): Ignore this event
08-26 12:57:30.879: D/SoftKeyboardDetect(329): Ignore this event
08-26 12:57:31.340: D/DroidGap(329): onMessage(onPageStarted,file:///android_asset/www/index.html)
08-26 12:57:31.500: D/szipinf(329): Initializing inflate state
08-26 12:57:31.500: D/szipinf(329): Initializing zlib to inflate
08-26 12:57:31.520: D/szipinf(329): Initializing inflate state
08-26 12:57:31.520: D/szipinf(329): Initializing zlib to inflate
08-26 12:57:31.570: D/szipinf(329): Initializing inflate state
08-26 12:57:31.570: D/szipinf(329): Initializing zlib to inflate
08-26 12:57:31.580: D/szipinf(329): Initializing inflate state
08-26 12:57:31.600: D/szipinf(329): Initializing zlib to inflate
08-26 12:57:34.670: I/SalesforceGapViewClient(329): Setting 'file:///android_asset/www/index.html' as the home page URL for this app
08-26 12:57:34.670: D/Cordova(329): onPageFinished(file:///android_asset/www/index.html)
08-26 12:57:34.670: D/DroidGap(329): onMessage(onNativeReady,null)
08-26 12:57:34.670: D/DroidGap(329): onMessage(onPageFinished,file:///android_asset/www/index.html)
08-26 12:57:34.889: I/Database(329): sqlite returned: error code = 14, msg = cannot open file at source line 25467
08-26 12:57:35.100: D/CordovaLog(329): Falling back on PROMPT mode since _cordovaNative is missing.
08-26 12:57:35.100: I/Web Console(329): Falling back on PROMPT mode since _cordovaNative is missing. at file:///android_asset/www/js/cordova/cordova-2.3.0.js:1110
08-26 12:57:35.130: D/CordovaNetworkManager(329): Connection Type: 3g
08-26 12:57:35.130: D/CordovaNetworkManager(329): Connection Type: 3g
08-26 12:57:35.130: D/DroidGap(329): onMessage(networkconnection,3g)
08-26 12:57:35.220: D/DroidGap(329): onMessage(spinner,stop)
08-26 12:57:35.330: D/dalvikvm(329): GC_CONCURRENT freed 911K, 53% free 3164K/6727K, external 2002K/2137K, paused 5ms+6ms
08-26 12:57:35.460: I/SalesforceOAuthPlugin.execute(329): action: getAuthCredentials, jsVersion: 2.0.0
08-26 12:57:35.460: W/SalesforceOAuthPlugin.execute(329): is being called by js from older sdk, jsVersion: 2.0.0, nativeVersion: 2.0.3
08-26 12:57:35.460: I/SalesforceOAuthPlugin.getAuthCredentials(329): getAuthCredentials called
08-26 12:57:35.470: I/SalesforceOAuthPlugin.getAuthCredentials(329): getAuthCredentials successful
08-26 12:57:35.540: D/CordovaLog(329): -----> Calling smartstoreClient:registerSoup
08-26 12:57:35.540: I/Web Console(329): -----> Calling smartstoreClient:registerSoup at file:///android_asset/www/js/entity/force.entity.js:46
08-26 12:57:35.550: D/CordovaLog(329): SmartStore.registerSoup: 'sobjects' indexSpecs: [{"path":"Id","type":"string"},{"path":"__local__","type":"string"},{"path":"Name","type":"string"},{"path":"attributes.type","type":"string"}]
08-26 12:57:35.550: I/Web Console(329): SmartStore.registerSoup: 'sobjects' indexSpecs: [{"path":"Id","type":"string"},{"path":"__local__","type":"string"},{"path":"Name","type":"string"},{"path":"attributes.type","type":"string"}] at file:///android_asset/www/js/cordova/cordova.force.js:479
08-26 12:57:35.560: I/SmartStorePlugin.execute(329): action: pgRegisterSoup, jsVersion: 2.0.0
08-26 12:57:35.560: W/SmartStorePlugin.execute(329): is being called by js from older sdk, jsVersion: 2.0.0, nativeVersion: 2.0.3
08-26 12:57:35.560: D/AndroidRuntime(329): Shutting down VM
08-26 12:57:35.569: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-26 12:57:35.580: E/AndroidRuntime(329): FATAL EXCEPTION: main
08-26 12:57:35.580: E/AndroidRuntime(329): java.lang.ClassCastException: com.salesforce.androidsdk.app.SalesforceSDKManager
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.app.SalesforceSDKManagerWithSmartStore.getInstance(SalesforceSDKManagerWithSmartStore.java:156)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.getSmartStore(SmartStorePlugin.java:401)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.registerSoup(SmartStorePlugin.java:300)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.execute(SmartStorePlugin.java:110)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.phonegap.ForcePlugin.execute(ForcePlugin.java:78)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:61)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:45)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:213)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.os.Looper.loop(Looper.java:123)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-26 12:57:35.580: E/AndroidRuntime(329):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 12:57:35.580: E/AndroidRuntime(329):     at java.lang.reflect.Method.invoke(Method.java:507)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-26 12:57:35.580: E/AndroidRuntime(329):     at dalvik.system.NativeStart.main(Native Method)


Best Answer chosen by Admin (Salesforce Developers) 
bhariharanbhariharan

This appears to be the problem:

 

08-26 12:57:35.569: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-26 12:57:35.580: E/AndroidRuntime(329): FATAL EXCEPTION: main
08-26 12:57:35.580: E/AndroidRuntime(329): java.lang.ClassCastException: com.salesforce.androidsdk.app.SalesforceSDKManager
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.app.SalesforceSDKManagerWithSmartStore.getInstance(SalesforceSDKManagerWithSmartStore.java:156)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.getSmartStore(SmartStorePlugin.java:401)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.registerSoup(SmartStorePlugin.java:300)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.execute(SmartStorePlugin.java:110)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.phonegap.ForcePlugin.execute(ForcePlugin.java:78)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:61)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:45)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:213)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.os.Looper.loop(Looper.java:123)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-26 12:57:35.580: E/AndroidRuntime(329):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 12:57:35.580: E/AndroidRuntime(329):     at java.lang.reflect.Method.invoke(Method.java:507)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-26 12:57:35.580: E/AndroidRuntime(329):     at dalvik.system.NativeStart.main(Native Method)

 

It appears that you're trying to typecast SalesforceSDKManager into SalesforceSDKManagerWithSmartStore. Can you check your app's initHybrid() call, and ensure that you used the one in SalesforceSDKManagerWithSmartStore, and NOT the one in SalesforceSDKManager?

All Answers

bhariharanbhariharan

This appears to be the problem:

 

08-26 12:57:35.569: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-26 12:57:35.580: E/AndroidRuntime(329): FATAL EXCEPTION: main
08-26 12:57:35.580: E/AndroidRuntime(329): java.lang.ClassCastException: com.salesforce.androidsdk.app.SalesforceSDKManager
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.app.SalesforceSDKManagerWithSmartStore.getInstance(SalesforceSDKManagerWithSmartStore.java:156)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.getSmartStore(SmartStorePlugin.java:401)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.registerSoup(SmartStorePlugin.java:300)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.smartstore.phonegap.SmartStorePlugin.execute(SmartStorePlugin.java:110)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.salesforce.androidsdk.phonegap.ForcePlugin.execute(ForcePlugin.java:78)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.api.CordovaPlugin.execute(CordovaPlugin.java:61)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.api.PluginManager.exec(PluginManager.java:224)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:45)
08-26 12:57:35.580: E/AndroidRuntime(329):     at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:213)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.os.Looper.loop(Looper.java:123)
08-26 12:57:35.580: E/AndroidRuntime(329):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-26 12:57:35.580: E/AndroidRuntime(329):     at java.lang.reflect.Method.invokeNative(Native Method)
08-26 12:57:35.580: E/AndroidRuntime(329):     at java.lang.reflect.Method.invoke(Method.java:507)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-26 12:57:35.580: E/AndroidRuntime(329):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-26 12:57:35.580: E/AndroidRuntime(329):     at dalvik.system.NativeStart.main(Native Method)

 

It appears that you're trying to typecast SalesforceSDKManager into SalesforceSDKManagerWithSmartStore. Can you check your app's initHybrid() call, and ensure that you used the one in SalesforceSDKManagerWithSmartStore, and NOT the one in SalesforceSDKManager?

This was selected as the best answer
agusagus
Thank you for replying, I found out myself too, but didn't read this until now. I'd like to add one thing though, there are issues when working with android 4.2.2 and 4.3, because this didn't show on those logs, and the app did not crash, but showed a blank screen.
bhariharanbhariharan

I'm guessing this is caused by a new version of the Android ADT plugin. Try the following steps:

 

Right click on your project in Eclipse, go to Build Path, and then Configure Build Path. Click on the Order and Export tab. Make sure Android Private Libraries and Android Dependencies are checked. Clean and rebuild all projects.

 

This should fix it.