Skip to Content

Hybrid Application Development with Visual Studio

Introduction

As you might heard Visual Studio is now also able to create and handle Cordova based applications. I watched some live demos and presentations on SAP TechEd 2015 in Barcelona. After that I tested the feature a bit in combination with SAP’s preferred solution for hybrid applications (cordova + Kapsel). I have to say that I was positively surprised about the way Microsoft integrated Cordova handling into the IDE.

Currently there is a cooperation between SAP’s mobile development teams and Microsoft going on, you can also read more about that, e.g. here: SAP Fiori Mobile Apps and Tools for Apache Cordova – The Visual Studio Blog – Site Home – MSDN Blogs

In the following I want to describe shortly how you can develop a Cordova based app which includes Kapsel plugins inside Visual Studio. Besides Windows as target platform (e.g. Win Phone, Win 8.1 or Win10), Android and iOS are also supported. Android and iOS apps can be executed on a web-based emulator (Ripple). Additionally, Android apps can be also executed on an x86 based emulator. Anyway, in the following I will primarily focus on hybrid apps for Windows 8.1 or Windows 10.

Preparation

I was using following versions

  • Visual Studio 2015 (Version 14.0)
    • There is a Community Edition available which is sufficient for hybrid app development, but please consider the license agreement
    • When installing Visual Studio make sure that you also checked the “HTML/JavaScript (Apache Cordova)” Option under option “Cross Platform Mobile Development”. Make also sure that you have installed all required components that are needed by Codova, e.g. nodejs, Java, GIT… If not you can also do this by using the Visual Studio installer…
      01_Prep_Visual_Studio.png
  • Kapsel SDK (SMP SDK SP10PL06)
  • Sample Kapsel SAPUI5 app from my GitHub repository (detailed steps are described below)
    https://github.com/MarvinHoffmann/kapsel
  • SMP Server SP09
    • Create an application on SMP (or HCPms) server which you can use later for connecting to. In my case the application is called “com.sap.mit.sample” and the endpoint is a simple OData sample service (http://services.odata.org/V2/Northwind/Northwind.svc/ ) SSO Mechanism is not really needed, because the OData service is not authentication protected. /wp-content/uploads/2015/12/02_smp_app_config_850505.png
      For Authentication I created a new security profile with a “System Login” authentication provider. Where I hardcoded a user named “Marvin” with password “test”. Do not use System Login modules in productive scenarios. This is only for testing purpose, because this tutorial does not cover security related topics.
      /wp-content/uploads/2015/12/03_smp_app_sec_850506.png

Creating Cordova App in Visual Studio

  1. Open Visual Studio 2015
  2. Choose File > New > Project… and choose template “Apache Cordova Apps” which is under option “JavaScript”. Highlight “Blank App (Apache Cordova)”, provide name and solution, then click on “OK”./wp-content/uploads/2015/12/04_visual_studio_cordova_project_creation_850507.png
  3. After the project got created, you can choose on which device type you want to execute this hybrid app (e.g. Android, iOS or Windows)./wp-content/uploads/2015/12/05_visual_studio_project_created_850508.png
  4. Choose “Debug” with “Windows-x64” as Solution Platform, then run on the “Simulator”.
    /wp-content/uploads/2015/12/06_visual_studio_project_run_850509.png
    On first time execution the platform “windows” will be added to the project (You can see this inside the Console Output. After that the simulator will start and will execute a “Hello-World” application./wp-content/uploads/2015/12/07_cordova_sample_app_run_850510.png
  5. We have a Cordova based application running. In the next step we should add Kapsel plugins, like the Logon and Logger plugin.

Adding Kapsel plugins

We now want to add some of SAP’s plugins, e.g. Logon and Logger plugin.

  1. As a prerequisite we have to tell Visual Studio where to find the Kapsel plugins, so that they can be integrated (during compile time). For that you can add a file named “config.json” in folder “.cordova” in the root of your project and add the following as content:

{
      "plugin_search_path": "C:\\Development\\KapselSDKSP10PL06\\plugins"
}

Of course the path here needs to be adapted to fit your environment, e.g. C:\SAP\MobileSDK3\KapselSDK\plugins

Be careful here, that there are no additional characters are added or a wrong encoding has been used, for best results create the config.json file with notepad and then copy the whole file into the “.cordova” folder. If there is a problem the compiler will directly throw an exception (e.g. Illegal character, or Parsing error, …)

/wp-content/uploads/2015/12/08_prerequesite_plugin_search_path_850511.png

If you skip this step you will run later (on compile time) into the error

Registry returned 404 for GET on https://registry.npmjs.org/kapsel-plugin-corelibs

2. We can add the kapsel plugins directly in Visual Studio. For that double click on config.xml which will load the cordova specific settings window and open menu entry “Plugins”

/wp-content/uploads/2015/12/09_config_plugins_850512.png

3. Now choose tab “Custom”, select option “local” and then navigate to the plugin you want to add, e.g. C:\SAP\MobileSDK3\KapselSDK\plugins\logon . After that click on “Add”.

/wp-content/uploads/2015/12/10_kapsel_plugin_add_850513.png

4. You can do the same for other plugins, e.g. the Logger plugin. On tab “Installed” you can see the currently installed custom plugins

/wp-content/uploads/2015/12/11_installed_plugins_850514.png

5. Now we need to add some coding to use these Kapsel plugins. For that you can clone my github kapsel repository ( https://github.com/MarvinHoffmann/kapsel ) or download the content as zip file. Copy the content of folder “KapselSampleRefSmall” into your www folder in Visual Studio. You can overwrite the existing index.html.

/wp-content/uploads/2015/12/12_project_structure_850515.png

6. The copied content is showing now how to start the Logon plugin. After successful onboarding a sample sapui5 based app is shown where we can perform some test operations, like sending a request. We will use the SAPUI5 resources and also the jquery version which got bundled together with the logon plugin. In this way we do not need to add these resources separately.

/wp-content/uploads/2015/12/13_index_html_850516.png

7. In file SMPHelper.js the app is getting initialized and also configured. So make sure that you are adapting the values here according to your environment:

/wp-content/uploads/2015/12/13_smphelper_connection_details_850517.png

8. Cordova will throw an event called “deviceready”. We set an event listener here and specify that the method “init” should be called if Cordova throws this event. In the init method we will call


sap.Logon.startLogonInit(context, appDelegate);

This will then start the LogonPlugin initialization process. When executing this first time ever (initial app run) a Logon UI is shown to the user. On subsequent app starts the successcallback is called directly without showing a UI to the user.

9. When running the app now specify your user and password into the logon screen. In my case I entered user “Marvin” and password “test”

/wp-content/uploads/2015/12/14_app_execution_850518.png

10. After clicking on “Registration” in the right top corner the logon plugin tries to perform a registration against the given SMP (or HCPms). If successful the following screen will be shown where the user can choose an app specific passcode. These passcode settings can be controlled by the app settings on SMP server. If no passcode policy is defined user can click here on “Disable app-passcode” and then again on the button in the right top corner “Continue”.

/wp-content/uploads/2015/12/15_app_passcode_850519.png

11. The app will start. The logon (or registration) process is successfully finished. In this sample app I show the logon plugin’s return values in a text area.

/wp-content/uploads/2015/12/16_app_registration_successful_850520.png

12. You can also see on your SMP (or HCPms) server that the logon plugin created a new connection for our user:

/wp-content/uploads/2015/12/17_smp_registration_850521.png

13. We are finished and have our first windows Kapsel application running…


Logo.png

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply