Skip to Content
Technical Articles
Author's profile photo Ferry Djaja

Add Machine Learning capabilities in SAP Fiori App with Google ML Kit Custom Model

We are going to build an Android Fiori App with SAP Web IDE to identify objects in images using Google ML Kit Custom Model. With the custom model, you can train your own ML model to recognize the objects according to your needs.


Follow my earlier blog to setup the local HAT with SAP Web IDE Full Stack and install the required cordova plugins:

  • cordova-plugin-ml
  • cordova -plugin-firebase
  • cordova-plugin-camera-preview

We will modify the cordova-plugin-ml and add some Java codes later on.

Don’t forget to setup the Firebase console project, download the google-services.json file and add into C:\Users\<user>\SAPHybrid\Scanner\hybrid\platforms\android\

In this tutorial, we will just use the existing ML model from Google codelabs.

Modify build.gradle 

Open build.gradle and add aaptOptions and the required dependencies:

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    implementation(project(path: "CordovaLib"))
    compile ""
    compile ""
    compile ""
    compile ""
    compile ""
    compile ""
    implementation ''

And sync the project.

Adding TensorFlow Lite Model to Project Asset Folder

We are going to use the existing model from TensorFlow. We can build our own custom model, you may refer to this tutorial how to do it.

We we will use the local version of the model for offline scenario.

Download the TF Lite model from here and extract.

Get the mobilenet_v1_1.0_224_quant.tflite.

For label, we need to get the label.txt from here.

Extract the code and get the label.txt from \mlkit-android-master\final\app\src\main\assets\

Now we have two files: mobilenet_v1_1.0_224_quant.tflite and label.txt.

Upload these files to the asset folder Android project.

Modify cordova-plugin-ml

Open from this location:

Update the code with

Call the Plugin

How to call this plugin? it is very easy, just call takePicture() JavaScript method from SAPUI5 XML view and get the result from recognizedText.blocktext.

takePicture: function() {
        quality: 100
    }, function(imgData) {

      mltext.getText(onSuccessText, onFailText, {
            imgType: 4,
            imgSrc: imgData

        function onSuccessText(recognizedText) {
            alert("Text: " + recognizedText.blocktext);

        function onFailText(message) {
            alert('Failed because: ' + message);

Now everything is setup, you can build the project and install the .APK onto you Android phone.

A complete source code can be found on my Git.

Thanks for reading and let me know if there is any question.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.