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
gbu.varungbu.varun 

Salesforce SDK authentication

Hi,

I am creating a Hybrid app for Android application. I installed Forcedroid Package from Github. There are some hybrid sample apps like: AccountEditor, ContactExplorer etc. I also created a new application. Everything is working fine. It has offline feature also.
But after sometime application stop working. I got uncaught error.
After deleting the cache and data of the application app asks for Salesforce username and password. And app start working again without making any coding change.

I think it is authentication issue due to Salesforce SDK. it does not refresh access token.
Can anyone help on this issue please?

It is my bootcnfig setting:
{
    "remoteAccessConsumerKey": "Salesforce Consumer Key",
    "oauthRedirectURI": "URL",
    "oauthScopes": ["api","web"],
    "isLocal": true,
    "startPage": "index.html",
    "errorPage": "error.html",
    "shouldAuthenticate": true,
    "attemptOfflineLoad": true
}
akhilesh_sfdcakhilesh_sfdc
What error message did you get? Is this happening again?

We are aware of one issue where if you install multiple sdk apps on an android phone, the app sometimes is not able to fetch the user account information and crashes. Not sure if that's the same issue for you. The fix for this will be coming in next version of SDK.
gbu.varungbu.varun
Hi Akhileas,

Thanks for your response. I am getting following error again and again:
D/CordovaLog(1069): Uncaught ReferenceError: error is not defined
E/Web Console(1069): Uncaught ReferenceError: error is not defined at file:///android_asset/www/cordova.force.js:336

App works fine but after some time it does not work. After changing IP this error comes. I have installed only one app on my android phone. Is it oauth issue?
gbu.varungbu.varun
Hi Akhileash,

Did you get chance to look at this issue. Please help it is urgent.

Thanks,
akhilesh_sfdcakhilesh_sfdc
It's hard to know based on this error. Couple more questions:

1) Did you run the AccountEditor sample as is that comes from forcedroid? Or did you make any change?
2) Are you using the default "remoteAccessConsumerKey" or did you create your own Connected app and using your custom key? If you are using a custom key, then make sure that "IP restriction" is disabled for your Connected App settings. You can change that setting under https://<salesforce instance>/app/mgmt/forceconnectedapps/forceInstalledConnectedAppList.apexp
3) Does this error happen when you switch from offline to online? Also, how long is the session expiry on your salesforce user account?
gbu.varungbu.varun
Hi Akhilesh,

Thanks for your response.

1) I am running AccountEditor sample as is that comes from forcedroid. I did not make any change in AccountEditor.html file.
2) I created my own Connected app and I am using my own custom key. I have disabled IP Restrictions. I put "Relax IP restrictions" in IP Restrictions setting.
3) Intially, I did not get this error when I switch from offline to online. This error comes after some time after token expiration.  I put session timeout to 15 min to test the functionality.

These are the screens of connected app setting and session setting:

User-added image

User-added image
gbu.varungbu.varun
Hi Akhilesh,

Thanks for your help. This issue has been resolved. This issue was due to cordova.force.js file. I replace this file with another cordova.force.js file. Now it is working fine.

Thanks,