I am all excited to tell you about the new Mobile Development Kit (MDK) extension built for Microsoft Visual Studio Code. This extension is now available to customers with the latest release of the MDK editor on SAP Web IDE.
Mobile development kit (MDK) is a feature of SAP Cloud Platform Mobile Services. If you are new to MDK, and want to know more about developing apps in a low code environment, I suggest you begin by going through the following blogs and tutorials.
https://blogs.sap.com/2017/09/26/rapidly-build-rich-native-mobile-apps-without-writing-any-code/
Mobile Development Kit Learning Journey
About Microsoft Visual Studio Code
Microsoft Visual Studio Code is a streamlined code editor with support for development operations like debugging, task running and version control. It aims to provide just the tools a developer needs for a quick code-build-debug cycle and leaves more complex workflows to fuller featured IDEs. For more details about the goals of VS Code, see
Why VS Code.
What does the MDK extension for VS Code do?
SAP Web IDE continues to be our main editor for mobile development kit applications. However, if you are an MDK app developer, this extension is designed to assist you throughout the app development lifecycle, to code, build and debug MDK apps quickly and efficiently in a local environment. It can connect to the device/emulator directly, so you can see the real apps at runtime. Currently, it is supported only on Mac systems.
It is based on the VS Code extension framework and consumes many core services supported by VS Code, such as workspace, language protocol, task, and so on. It also introduces a new MDK language, and a new debugging process.
Tool Comparison
A common use case is to start your application using the MDK plugin as part of SAP Web IDE Editor and take advantage of the low code and highly productive environment.
Build pages, drag and drop controls onto the page and map to actions, backend data, etc. Then use the MDK extension within VS Code to debug certain parts of your application such as your business logic rules.
Using a Git repository synchronizes the latest MDK application changes between Web IDE and VS Code and allows developers to enjoy the best part of each tool.
What are the features available?
All the features listed here are available with this extension:
- Editing MDK Metadata JSON:Based on a comprehensive MDK schema definition, this feature detects an application node within the workspace, and supports operations like auto-completion, validation, and navigation.
- Coding MDK Rule JavaScript:Based on a predefined IClientAPI typing definition; this feature lets you use JSDoc snippets to describe rule arguments. It also supports operations like auto-completion, validation, and navigation for the IClientAPI.
- Bundling MDK Application:This feature integrates MDK metadata bundling process into the VS Code build task, from which you can generate VS Code specific bundle.js with information about the source maps, without interrupting the development process. Each time you save your work, the bundler process is started and runs in the background to speed deployment to the client. See Source maps for detailed information.
- Debugging MDK rule JavaScript:By leveraging a third-party NativeScript debugger, this feature lets you set breakpoints in rule files directly. This helps the debug process for MDK applications and allows you to easily move back and forth between building and debugging.
- Speed Deployment to a local MDK SDK Client App:The MDK extension for VS Code connects to a configured and running MDK client application. This application is on the local machine and is specified in the VS Code launch configuration. The NativeScript debugger will then automatically use this application for debugging purposes. Having a connected and local MDK application also speeds the repetitive nature of development and testing.
- Creating MDK metadata object:
Create an MDK metadata object by using the command palette, or by using the context menu.
What are the Prerequisites?
- For developing or modifying your app, you must have a Mac environment and must have installed VS Code version higher than 1.24.0.
For debugging your app, you must have the following:
- Install XCode, which is required to find the corresponding iOS simulator
- Install NativeScript CLI (by running the npm install -g nativescript command), which is required to trigger the tns command to launch an MDK app.
- The tns project for the MDK-branded client, which hosts the MDK app and supports the tns launch.
How do you work with the extension?
Installation:
- From the SAP Marketplace, download the latest version of vsix package folder, vsc-extension-mdk. This folder contains all the files necessary for your extension.
- Launch VS Code and from the Extensions viewer, select Extensions > Install from VSIX. The installation might take up to two minutes.
- Reload VS Code to enable the extension. A new language mode called MDK is attached to any open MDK metadata file.
Usage:
- The new MDK language introduced for VS Code shows property suggestions and auto-completes the text when you are typing.
- The MDK extension provides a convenient method for file navigation. The new language supports the following file types- .action, .app, .global, .page, .js, .service, .properties, .css, .nss.
- Place the cursor within the value of a file reference and select Go to Definition from the context menu, to open the file specified by the file reference.
- Select Peek Definition from the context menu to see the content of the file specified by the file reference in the editor.
-
3. Validation: If the metadata file which you have opened in the editor contains errors, such as a missing required property, incorrect value of the property _Type, non-existent file reference etc., error messages are displayed in the PROBLEM view. These error messages also appear in the editor when you hover over the tilde adjacent to the incorrect value.
4. Bundling:
- After you have modified your MDK app, you must bundle the app metadata and JavaScript files for the metadata to be interpreted correctly by the MDK client app at runtime. At this stage, an auto-bundling process is triggered when you click File > Save, if there are no validation errors.
- You can also manually trigger the bundling process at any time on any MDK file, by selecting Tasks > Run Build Task... or Run Task...
5.
Debugging:
- For debugging your MDK app, you must have bundled your app and added your own debug configuration or altered the existing one by modifying the launch.json file. Generate the default launch configuration file (launch.json) by clicking the gear icon in the Debug view, and choose the MDK debug configuration. In the generated launch.json file, specify the attribute appRoot as the NativeScript project path that corresponds to your branded MDK client app, and save the file.
- For quickly launching your app without debugging, click Debug > Start Without Debugging. See the progress report in the Debug Console. Once the launch is complete, the configured MDK client app will be launched in the default simulator.
- To debug your rule JavaScript files, click Debug > Start Debugging. See the progress report in the Debug Console. You can perform a couple of functions with the extension during debugging:
- Set breakpoints in rule files directly, by clicking on the left margin of the editor. Trigger actions like enabling, disabling, or reapplying breakpoints from the Breakpoints section of the Debug view.
- Check the variables or the call stack when stopping at some breakpoint.
- Trigger debug actions like Continue/Pause, Step Over, Step Into, Step Out, Restart etc. in the floating debugging bar.
- Stop the debugger execution by clicking the Disconnect or Stop button in the floating bar.
Note: Don’t Accept Updates from Mobile Services
This caused me to stumble and ask for help, so I am making sure to share this information with you. While building and debugging from MDK apps from VS Code, avoid updating the MDK Client on your local machine with app updates from SAP Cloud Platform Mobile Services.
Once your MDK client receives an update from Mobile Services, the local bundle file from VS Code is disabled and doesn’t display app updates you have made from within VS Code.
If you have already updated this file, reset or reinstall your app on the iOS simulator, follow the onboarding process again and do NOT accept the update from Mobile Services.
Next Steps
Now, take a look at the following documentation to learn how to get started and build your first application with the MDK extension for VS Code.