如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

There is a wonderful tutorial Building SAP Fiori-like UIs with SAPUI5 in 10 Exercises written by Bertram Ganz.

In this blog, I will show step by step how to package the UI5 application built by this tutorial as a native application into your Android device.

Here below are some screenshot of this UI5 running in my mobile phone.

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上
如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

(1) install nodejs in your laptop, and add the installation folder to your environment variable.

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

(2) Install Cordova via npm -g install cordova:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

(3) Create a new folder. And then go into this folder, create a new Cordova project via the following command:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

Then a skeleton project with those files and folders are automatically created.

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

Platforms folder is empty so far since I don’t add any mobile platform yet.
(4) Add android platform support via command: cordova platform add android

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

Once done, the necessary artifacts (Android platform specific) for APK generation are created under folder platforms/android.

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

Now you should have the folders with the following hierarchy:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

(5) By default there is a dummy index.html file existing in folder www. Using command cordova prepare, the index.html will be copied automatically to folder platforms\android\assets\www. So the general idea here is we always develop the artifacts of our web application in www folder. Once done, use cordova prepare to synchronize it to android platform related folder.

Then use command cordova compile, and you will see the APK file generated successfully.

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

You might meet with the error message below during compile:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TGznex9F-1598619431139)(https://upload-images.jianshu.io/upload_images/2085791-16bcff409a2e7c77.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)]

In this case just download the binary version of gradle, unzip it and configure the executable file path in your PATH environment variable:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

Install the APK into your mobile device and you should see the following picture:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

(6) I have uploaded my test Fiori application to my github.
Download folder scn_exercise and index.html from folder www, and copy it to your folder www in your local project.

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上
如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

(7) Once done, execute cordova prepare and cordova compile once again, and the new APK will be created. Install it to your device to see final result.

Note: although the Fiori application itself can work offline with a mocked data model, in order to reduce the size of packaged APK file, I didn’t package UI5 library to the APK, but instead declare a reference to UI5 library with online version, which means when you test this application in your mobile phone, it is a must that your phone should have internet access.

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

If you don’t have an Android device, you can also test it in Emulator ( you have to install Android development studio first )
Create a new virtual device and launch it:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

Then use the following command to install the APK into emulator:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

Now you can test the application in emulator:

如何使用Cordova将SAP Fiori应用打包并安装到Android平台上
如何使用Cordova将SAP Fiori应用打包并安装到Android平台上

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
如何使用Cordova将SAP Fiori应用打包并安装到Android平台上