You are here: Building and Viewing an Application > Integrate React Native App into a Kony App

Integrate a React Native App to a Kony App

Applies to Kony Visualizer Classic.

Using this feature, you can integrate a React Native app (which is developed in React Native framework) to a Kony app (which is developed in Kony framework). The React Native app is embedded into the Kony form through a container, called as the React Native Container. Furthermore, some APIs are used to communicate between the React Native app's JavaScript framework and the Kony app's Kony framework. This feature is available from Kony Visualizer V8 SP4 onwards.

React Native is a framework developed by Facebook. React Native is used to create cross-platform mobile applications.

To gain a more hands-on experience on the React Native Integration process, download and use the TaskListSample app from GitHub.

For more information on the container and communication APIs that are essential to integrate a React Native app to a Kony app, refer these sections:

Prerequisites

Before you try to integrate the React Native app into your Kony project, ensure that you compile the reactNative project and run it at least once (by which you can confirm that the project is error-free).

Requirements for the React Native Project

For integrating the reactNative app into your Kony project, the requirements for the reactNative Project are as follows:

Note: For iOS, the application code inside the React Native AppDelegate class is ignored. Multiple apps must not have the same class files or classes with the same name.

Manually Integrate a React Native App to a Kony App

In this section, you will learn how to integrate a React Native app to a Kony app manually.

Important: Currently, Kony Visualizer does not provide the support to directly integrate a React Native app to a Kony app. As a result, you must perform the steps mentioned in the following sections to execute the integration process.

Common Steps

  1. In the root folder of your Kony application workspace, create a folder and name it as ReactNativeProjects.

  2. Copy the React Native app(s) to the ReactNativeProjects folder.
    For iOS, follow these steps:

    1. Create a package.json file in the ReactNativeProjects. This json file must contain a JSON object with a single key-value pair, where the key is dependencies and its value is an array of react-native dependencies mentioned in each package.json file of all the React Native apps. For example,
      //package.json file content
      {
      "dependencies": ["react","react-native","react-navigation"]
      }

    2. If the React Native apps contain pod dependencies, create a pod file in the ReactNativeProjects folder and mention all the pod dependencies for all the React Native apps, with the target as KRelease inside the pod file.
  3. Run the following platform-specific React Native command from each ReactNative app root folder to generate the hierarchical JavaScript bundle:

    • For Android:
      react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/<AppName>/index.android.bundle --assets-dest android/app/src/main/res

    Note: Create the assets folder (under <reactNativeApp>/android/app/src/main/) and also <AppName> folder under assets, if they do not exist.

    • For iOS:
      react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/<AppName>/main.jsbundle --assets-dest ios

    Note: Replace <AppName> with the app's name key value that is available in the app.json file, which is located at the root folder of the each React Native project.

Enable React Native for Andorid

You can enable the React Native feature for Android by adding its corresponding properties to the androidbuild.properties file. For detailed information on the manual steps of this process, click here.

Enable React Native for iOS

The manual steps to enable the React Native feature for iOS are as follows:

  1. In Kony Visualizer, go to Product > Build, select the iOS Build option, and then click Build.
  2. In the Console, a link will be generated, which is the path to the created KAR file.
  3. Click the link. The KAR file location opens.
  4. Rename the konyappiphone.KAR file to konyappiphone.zip
  5. Unzip the konyappiphone.zip file, and then paste the ReactNativeProjects folder (which is present at root folder of app. workspace) in the unzipped folder.
  6. Compress the contents of the unzipped folder to create an archive (zip).
  7. Rename the zip with extension as KAR; this creates a KAR file that contains React Native apps.
  8. Navigate back to Visualizer, go to Product > Run As, and then select the iOS emulator. The relevant logs in the Console are generated.
  9. In the Console, a link to the path of VMAppWithKonylib is created.
  10. Click the link to open the VMAppWithKonylib location.
  11. Go to the gen folder inside the VMAppWithKonylib folder in the terminal.
  12. Enter the perl extract.pl modified_KAR_file location command to perform the KAR file extraction.
  13. After the Perl extract is complete, under the Edit Scheme Build options, deselect the Parallelize Build option for the release scheme.
  14. For pods after the Perl extract, the VMAppWithKonyLib.xcworkspace file will be created; use this file to build the application.
    If this file is present, the you must add the $(inherited) flag under the Other Linker flag setting.
  15. The third-party React Native libs that depend on pods should set the Framework Search Path, Library Search Path, and Header Search Path as $(SRCROOT)/../../../../../Pods/ recursive.
  16. If the pods require any specific build settings, such as enable modules, deployment target, and swift version, you must set them.
  17. If the third-party React libraries have specific fonts, you must add those files to the project and also to the Info.plist file.
  18. If the app depends on any other framework or library file other than pods, you must add them to the project.
  19. If you are building in DEBUG mode, set BUILD ACTIVE ARCHITECTURES to YES.

Resolutions for Android Build Failure Issues

For Android, React Native apps are added as libraries to the Kony app, which might result in the failure of the build due to many reasons. Here are a few build failure issues when the React Native app is embedded and built for Android:

Note: The Build Tools versions are mentioned in the app module build.gradle file.

android {
        ..........
    buildToolsVersion '27.0.3'
}

Kony's Gradle Plugin, Build Tools, and Gradle Dependencies

The relevant information on Kony's Gradle Plugin, Build Tools, and Gradle Dependencies for V8 SP4 is as follows.

Note: The versions will change based on the plugins, so always refer the plugin corresponding to the build.gradle file for the exact Kony versions used .

Location of the build.gradle file: <workspace>/temp/<appName>build/<luaandroid/luatabrcandroid>dist/<appName>:

/** gradle android plugin version **/

classpath 'com.android.tools.build:gradle:3.2.1'

/** compileSDKVersion **/

28

/** build_tools_version **/

28.0.3

/** gradle version **/

gradle 4.6

/** support library dependencies **/

implementation 'com.android.support:recyclerview-v7:28.0.0'

implementation 'com.android.support:appcompat-v7:28.0.0'

/** Google play services dependencies versions **/

//maps

implementation 'com.google.android.gms:play-services-maps:11.6.0'

//locationlibversion

implementation 'com.google.android.gms:play-services-location:11.6.0'

//multidex_dependency

implementation 'com.android.support:multidex:1.0.0'

//dependencies_google_play_wearable_version

implementation 'com.google.android.gms:play-services-wearable:11.6.0'

//dependencies_android_support_wearable_version

implementation 'com.google.android.support:wearable:2.0.2'

//dependencies_android_wearable_wearable_version

compileOnly 'com.google.android.wearable:wearable:2.0.2'

//dependencies_google_fcm_messaging

implementation 'com.google.firebase:firebase-messaging:11.6.0'

//dependencies_google_play_pay_version

implementation 'com.google.android.gms:play-services-wallet:11.6.0'

//classpath_google_services

classpath 'com.google.gms:google-services:3.1.0'

Copyright © 2013 Kony, Inc. All rights reserved.