• Introduction
  • Dev Environment Setup
  • Developing Apps
  • Data Handling
  • Device Capabilities
  • Testing & Debugging
  • Extending

Using Rhodes app in Native Mobile app

Rhodes framework since v7.1 allows to build your Ruby/NodeJS Rhodes app as standalone lib and to use this lib within native Android, iOS or Windows Desktop/Tablet applications. It can be useful in the following cases:

  • Development new cross-platform application with native UI and extracting platform independent business logic to Rhodes Ruby/JS app;
  • Reusing business logic from existing Rhodes app in new native Android, iOS or Windows Desktop/Tablet applications.

How it work

Rhodes standalone lib provides a few ways to connect a native code and Rhodes local server Ruby code.

  • Special new Rhodes API for direct calls of Ruby code (ObjC API for iOS, Java API for Android, C++ API for Windows)
  • HTTP request to local server to call controller Ruby code

Native App with Rhodes app as standalone lib architecture

Building Rhodes Framework as standalone lib for your app

There we build Rhodes framework as standalone lib for the target platform and with all extensions in build.yml of your app. It must required each time when you change build.yml: change included extensions for example.

iOS

rake build:iphone:rhodeslib_framework[“<path to your native iOS app folder>”]

Android

rake build:android:rhodeslib_lib[“<path to your native Android app folder>/app/libs/”]

Windows

rake build:win32:rhodeslib_lib[“<path to your native windows app folder >/RhodesApp”]

The dll with suffix “d” will be created if option build is set to ‘debug’ in build.yml. Necessary header files will be placed to rhoruby folder.

Building Rhodes application bundle

iOS

rake build:iphone:rhodeslib_bundle[“<full path to your native iOS application folder>”]

The command prepares Rhodes application bundle and puts it to root of XCode project folder. The folder RhoBundle should be placed in root of XCode project folder.

if you want to use the framework standalone lib and the you application bundle in your already existing XCode project make next steps after generate the framework lib and app bundle:

  • open your native project in XCode;
  • Drag and Drop the bundle folder to root of your XCode project and make reference to folder option;
  • Drag and Drop the framework lib to root of your XCode project, add the framework lib to the embedded binary list (general option of project);

Android

rake build:android:rhodeslib_bundle[“<full path to your native Android application folder>/app/src/main/assets/”]

The command prepares Rhodes application bundle and puts it to your Android project folder.

if you want to use the framework standalone lib and the you application bundle in your already existing Android project make next steps:

  • Make dir /app/libs/ in your Android app if it doesn’t exist;
  • Make dir /app/src/main/assets/ (from shell or from Android Studio: right menu button on app item and -> new -> folder -> Assests Folder);
  • Prepare Rhodes framework standalone lib and Rhodes application bundle by rake commands described above;
  • In build.gradle in section dependencies add the next:
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation(name:'<app name>', ext:'aar')

where <app name> is bundle name.

  • In AndroidManifest.xml in section application add the next:
android:name="com.rhomobile.rhodes.RhodesApplication"
  • Sync Project with Gradle Files
  • Build Android project

In sources:

  • Main Activity must be extends from com.rhomobile.RhodesActivity
  • Extends RhoMain in own class for get event about starts Rhodes application - onAppStart() method. Example:
class DefaultMain extends RhoMain
{
    @Override
    public void onAppStart()
    {
        super.onAppStart();
    }
}
  • In main Activity within OnCreate add code for setup Rhodes:
RhodesService.setRhoMain(new DefaultMain());

onAppStart() will be called when Rhodes application(server) already started.

  • Build and run your Android project

Windows

rake build:win32:rhodeslib_bundle[“<full path to your native windows application folder>/RhodesApp”]

The command builds and compile of the bundle by set path. The Bundle will be placed to RhodesBundle folder.

Further connection of the library is no different from the connection of any other library. That is, the path to .lib (stub for .dll) and the path to headers are always indicated, depending on the IDE, this may look like differently, for an example with Visual Studio, look in rhodes_lib_examples / NatvieWindows.

Examples

You can find complete examples for iOS, Android and Windows Desktop/Tablet in this repo. Please read carefully README.md for detail instructions.

Back to Top