Thursday, November 6, 2014

Android Hybrid Mobile App with Salesforce SDK basic setup

SYSTEM REQUIREMENT  


1. Windows Machine
2. Java (Please make sure JAVA_HOME path is set up)
3. Apache Ant
4. Git
5. Eclipse with Android SDK
6. SalesforceMobileSDK-Android

SET UP ANT 


1.Download Apache Ant Zip File From  http://ant.apache.org/bindownload.cgi
2.Extract Zip to any of your System drive.


3.Set up ANT_HOME. 



Go to  Control Panel ->  System ->  Advanced System Setting - > Advanced - > Environmental Variables

To check Ant is properly set up go to command prompt ant type ant –version. If it shows version then
ant has been properly set up.

SET UP GIT  

  • Download git from http://git-scm.com/downloads
  • Install git  

SET UP ANDROID BUNDLE 

  • Download Android ADT bundle from http://developer.android.com/sdk/index.html 
  • Extract the zip file to a Drive in a folder 
  • This bundle will contain Eclipse with ADT plugin, Android SDK.
  • Set up Android SDK. Download Android 2.2. Open  Eclipse go to Window - > Android SDK Manager.  
  • Select Tools, Android 2.2 and all its component Click install packages.


(I have already installed Android 2.2 that is why it is not counting its packages, please don’t be confused)

  • Set up Emulator, in Eclipse go to Window -> Android Virtual Device Manager - > New fill all the details 


SET UP SALESFORCE MOBILE SDK

  • Open Git Bash. Go to a folder where you want Salesforce SDK to be copied.  Type git clone https://github.com/forcedotcom/SalesforceMobileSDK-Android.git press Enter 

  • Salesforce Mobile SDK is now copied to your system. Now go inside the folder type ./intall.sh press Enter. 

  • This is an additional step but I prefer you should do it. Go to same location in command prompt type install.vbs

 Keep clicking “Ok” on all the popups which will pop out.  

  • Open Eclipse now click file import -> General -> Existing project into workspace on browsing the root directory go to salesforce sdk and import. 

It will show some Errors please follow these steps.
  • Right click on SalesforceSDK go to Android Tools - > Fix project properties.
  • Go to project properties -> Android make sure Android 2.2 is checked.
  • Now there will be 4 other errors like 


  • For the first one. Double click the error it will open encryption.java file comment the line no 74 where there is error save it. You will see 2 errors are gone. Now in the same file change Build.VERSION_CODES.HONEYCOMB to Build.VERSION_CODES.FROYO saves. 

  • SCREENLAYOUT_SIZE_XLARGE double click it, it will open ForceApp.java file change it to SCREENLAYOUT_SIZE_LARGE save now all error are gone, there will be some warnings ignore it. 

CREATE A HYBRID APP  


HYBRI D LOCAL APP (ALL THE HTML AND JS WILL BE I NSIDE THE APP CONTAI NER)



Open command prompt go to salesforceMobileSDK location  type 


Ant create_hybrid_local -Dapp.name={appName} -Dtarget.dir={targetDir} Dpackage.name= packageName} [-Duse.smartstore=true]

  • appName:-Name of your App
  • targetDir:- App location in your system 
  • packageName:- type some package name for example com.myapp  
  • smartstore:- if you are creating a app having capability of offline storage make it true or else don’t include it . (Advised that you should not go for offline version at start up) for example in commond prompt
C:\AndroidDev1\SalesforceMobileSDK-Android> ant create_hybrid_local -Dapp.name=MyApp -Dtarget.dir=C:\MyMobileApps\FirstApp -Dpackage.name=com.myapp 


  • Now in Eclipse File->Import->General->Existing project into workspace now in root directory go to target directory of your project, import the project (From above example it is “FirstApp”). 
  • Now Right click your project, go to properties -> Android check android 2.2 and add SalesforceSDK as library.

  • After that in your project go to bootconfig.js file which will be in folder assets/www of your project.
  • Set consumer key and redirect URL according to your remote access or connected app.  










  • Now the app set up is done. Start your app coding from index.html page in the same folder.  
  • To run the App Right click on it Run As -> Android Application. Enjoy !!!!!!

HYBRI D REMOTE APP (ALL HTML AND JS WI LL BE ON SALESFORCE) 


Open command prompt go to salesforceMobileSDK location  type 
Ant create_hybrid_vf - Dapp.name={appName} -Dtarget.dir={targetDir} Dpackage.name={packageName} -Dapex.page={apexPage} [-Duse.smartstore=true]

  • appName:- Name of your App
  • targetDir:- App location in your system
  • packageName:- type some package name for example com.myapp 
  • apexPage:- Specify which VF should be opened at the start of the app.
  • smartstore:- if you are creating a app having capability of offline storage make it true or else don’t include it . (Advised that you should not go for offline version at start up)

for example in commond prompt  
C:\AndroidDev1\SalesforceMobileSDK-Android> ant create_hybrid_vf  -Dapp.name=MyApp -Dtarget.dir=C:\MyMobileApps\FirstApp -Dapex.page=/apex/VFpage -Dpackage.name=com.myapp  

  • Same as step 2 of previous one.
  • Same as step 3 of previous one.
  • Same as step 4 of previous one
  • Now the Setup is done. You can start coding your VF page and the related page in your SF org.
  • To run the App Right click on it Run As -> Android Application. Enjoy !!! 
  

No comments:

Post a Comment