Ruboto: Quick Start

What is Ruboto?

Ruboto (Ruby on Android) is a platform for developing full stand-alone apps for Android, using the Ruby language and libraries. Most Android development is done in Java. With Ruboto, the complete APIs of Android, Java, and Ruby are available to you using the Ruby language.

Setting Up a Ruboto Development Environment

Probably this is the most cumbersome process and the documentation is quite confusing. So be patient!

We shall setup the Ruboto Development Environment for Windows. For other operating systems, please refer to Environment setup for Ubuntu and Environment setup for Gentoo.

JDK

You can use any version of JDK (>=6). If you don’t have a JDK, download the latest stable version of JDK 7 (or Java SE 7). I downloaded the file jdk-7u51-windows-i586.exe (for Windows). I then installed both the development tools and the public JRE. Next set the system environment variables classpath, path and JAVA_HOME once. This is what I have on my Windows 7 PC:

path=%path%;d:\Java\jdk1.7.0_51\bin;
classpath=%classpath%;.;
JAVA_HOME=d:\Java\jdk1.7.0_51

It could be different on your PC.

Install a Ruby implementation

Ruboto works with all major Ruby implementations like Ruby MRI, JRuby, Rubinius. We shall use JRuby here.

Download the JRuby distribution. I downloaded the file (for Windows) jruby_windows_1_7_10.exe. Run the jruby_windows_1_7_10.exe file and select the default options. I installed JRuby in my folder D:\jruby-1.7.10

To test that JRuby is working, in a new command window type:

jruby -v

The output is:

jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) Client VM 1.7.0_51-b13 [Windows 7-x86]

Close the command window.

Ruboto

To install ruboto, in a new command window type:

jruby -S gem install ruboto 

Now close the command window.

Through ruboto you can:

  • Generate a new Ruboto/Android application directory
  • Generate additional Ruboto components for your existing application
  • Update the Ruboto components of an existing application
  • Add JRuby to your existing application
  • Set up or check your development environment
  • Set up and/or launch an emulator

Ant

Android ships with its own version of Ant, but Ruboto will need to access Ant as well from its own scripts. If you don’t have a stand-alone version of Ant installed (version >=1.8.1 is required), download it and unzip to any folder. Again, add its bin folder to your PATH.

path=d:\apache-ant-1.9.3\bin;

Make sure you can run the Ant command.

Android SDK

Install the Android SDK Tools for Windows. Click on “DOWNLOAD FOR OTHER PLATFORMS” and download the file installer_r22.3-windows.exe Now in a new command window, execute this .exe file and use the default options. I installed the Android SDK in the folder D:\Android\android-sdk During the installation process, it will ask you whether to Start SDK Manager. Select Start SDK Manager and click on Finish. The Android SDK Manager screen opens up with some packages pre-selected.

As a minimum configuration for your SDK, it is recommended that you install the following:

  • The latest Tools packages (check the Tools folder).
  • The latest version of Android (check the first Android folder).
  • The Android Support Library (open the Extras folder and check Android Support Library).

Click on the Install button.

Here’s what I have installed on my PC:

The Android SDK Manager
The Android SDK Manager

Next set the system environment variable ANDROID_HOME=D:\Android\android-sdk Add the following to the system environment variable path

path=D:\Android\android-sdk\platform-tools;D:\Android\android-sdk\tools;D:\Android\android-sdk\build-tools\18.1.1;

Now check your Environment Setup via the command:

$ ruboto setup

ruboto setup should download and install the missing components, if any, needed for Android and Ruboto development.

Generate an Android Virtual Device (AVD)

android is an important development tool that lets you:

  • Create, delete, and view Android Virtual Devices (AVDs).
  • Create and update Android projects.
  • Update your Android SDK with new platforms, add-ons, and documentation.

First, let us list out the available targets. Open a new command window and type:

$ android list target
Available Android targets:
----------
id: 1 or "android-10"
     Name: Android 2.3.3
     Type: Platform
     API level: 10
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
     ABIs : armeabi, x86
----------
id: 2 or "android-18"
     Name: Android 4.3
     Type: Platform
     API level: 18
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
     ABIs : armeabi-v7a, x86
----------
id: 3 or "android-19"
     Name: Android 4.4
     Type: Platform
     API level: 19
     Revision: 1
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
     ABIs : armeabi-v7a
----------
id: 4 or "Google Inc.:Google APIs:19"
     Name: Google APIs
     Type: Add-On
     Vendor: Google Inc.
     Revision: 1
     Description: Android + Google APIs
     Based on Android 4.4 (API level 19)
     Libraries:
      * com.google.android.media.effects (effects.jar)
          Collection of video effects
      * com.android.future.usb.accessory (usb.jar)
          API for USB Accessories
      * com.google.android.maps (maps.jar)
          API for Google Maps
     Skins: WVGA854, WQVGA400, WSVGA, WXGA800-7in, WXGA720, HVGA, WQVGA432, WVGA
800 (default), QVGA, WXGA800
     ABIs : armeabi-v7a

Now generate an AVD unless you want to develop using your phone. Type:

$ android -s create avd -f -n Android_4.3 -c 1000M -t android-18 --abi x86
Android 4.3 is a basic Android platform.
Do you wish to create a custom hardware profile [no]no
Created AVD 'Android_4.3' based on Android 4.3, Intel Atom (x86) processor,
with the following hardware config:
hw.lcd.density=240
vm.heapSize=48
hw.ramSize=512

The various options that we have used are:

-s   Silent mode. Only errors are printed out.
create avd -n <name>   Creates a new Android Virtual Device (AVD) by that name. This is required.
-f   Force creation of the AVD.
-c   the size of a new SD card image to create for this AVD
-t <targetID>   Target ID of the system image to use with the new AVD. This is required.
--abi x86   The Application Binary Interface (ABI) to be used.

Note: I tried using armeabi-v7a in place of x86 on Windows but it fails.

For the most current list of options, in the already open command window type android –h

You can find more information on The Application Binary Interface (ABI) here.

Let’s check our AVD. Type:

$ android list avd
Available Android Virtual Devices:
    Name: Android_4.3
    Path: C:\Users\TALIM\.android\avd\Android_4.3.avd
  Target: Android 4.3 (API level 18)
     ABI: x86
    Skin: WVGA800
  Sdcard: 1000M

Start your emulator

The emulator is a virtual mobile device that runs on your computer. The emulator lets you develop and test Android applications without using a physical device.

This is only required if we are going to use the emulator and not develop using our actual device. Ruboto offers a command to help you create and run the emulator for a given version (api-level) of Android. In the open command window, type:

$ ruboto emulator -t android-18

The emulator boot hasn’t completed until you see the Android home screen with icons; this might take a couple of minutes. You should finally see something like this:

Emulator
Emulator

Creating a Ruboto project

Ruboto will create an Android project from scratch for you, which ensures that your manifest is set up correctly, scripts are placed in the right collection, and you have access to the necessary libraries. You should take this approach rather than trying to create it yourself or modifying an existing Android project.

To create a sample project, open a new command window and move to a project folder say d:\ruboto. Now type the following:

D:\ruboto>ruboto gen app --package org.ruboto.example.quick_start --target android-18

gen app tells Ruboto to create a new Android project from scratch
--package provides the unique Android package name. Your project is created in the quick_start folder below your current folder d:\ruboto
--target specifies which Android version to compile the project against

Modify the generated .rb file

The main activity of the application resides in our application’s d:\ruboto\quick_start\src folder. I have slightly modified my main activity file quick_start_activity.rb (the file is named with our application name):

Build, Install and Run the default application

With the emulator running, you can install and start your new Ruboto application.

Note: There’s a workaround for Windows as suggested by Adam Parrott @Axianator

Please do the following first:

  1. Locate the Android SDK build-tools directory being used by Ruboto. For me, this directory is located at d:\Android\android-sdk\build-tools\18.1.1.
  2. Open the dx.bat file in your preferred text editor.
  3. On line 53 of dx.bat, copy the set defaultXmx line modified by Ruboto and paste it below on line 54.
  4. Change the pasted value on line 54 from 2048M to the original 1024M.
REM By default, give dx a max heap size of 1 gig and a stack size of 1meg.
rem This can be overridden by using "-JXmx..." and "-JXss..." options below.
set defaultXmx=-Xmx2048M
set defaultXmx=-Xmx1024M
set defaultXss=-Xss1m

Adding the duplicate Xmx line allows you to set your own Xmx value while tricking Ruboto into thinking the dx.bat has already been modified with it’s own Xmx value (thereby ignoring whatever changes you make yourself).

If you find 1024M is too small for this variable, you can experiment with any number between the original 1024M and the problematic 2048M values. I find that the original 1024M value works fine on my machine for most projects. However, your mileage may vary.

In the already open command window, type:

$ cd quick_start
$ rake install start

After a few seconds you see the following in the command window:

BUILD SUCCESSFUL
Total time: 8 seconds
adb shell date -s 20131120.102437
Wed Nov 20 10:24:37 EST 2013
Installing package org.ruboto.example.quick_start
        pkg: /data/local/tmp/QuickStart-debug.apk

Success

526 KB/s (74474 bytes in 0.138s)

Note: The first time you install a Ruboto application on the device/emulator, Ruboto will ask for you to install the Ruboto Core Platform. You should see something like this in your emulator:

Emulator
First Ruboto application being installed

Click on the image on your emulator (as seen in the screenshot above). After some time, you will see a Down arrow at the top-left corner (it should not be flickering). On your Home screen, display all the apps. Double-click on Downloads. You would see a screen like:

Emulator
Download complete

Single-click on this and you should see:

Emulator
Install Ruboto Core

Click on the Install button. After sometime Ruboto Core gets installed on the emulator. Click on the Done button. On the Home screen, double click on the Quick Start app. You should now see:

Emulator
Sample Ruboto App

Our sample application can now be executed. Click on the Click Me button and you should see a final screen as shown:

Emulator
Our Sample App Running

Congrats!

Other install options

If you’re using a device, you have other good options. You can copy the apk into your Dropbox folder, open the Dropbox app on your device, and open the apk, which will initiate the install process. You can also upload it to a GitHub repository’s downloads section, which now gives QR’s for .apk files. Just scan the QR with the barcode scanner app on your phone.

You also have the option to mount your SD card as a drive on you machine, copy the apk to the drive, unmount the disk and use AppInstaller (free app) to install the apk.

A Request: I don’t have an Android phone with me and would request someone who has one, to install the QuickStart-debug.apk file created for this blog post on his/her device. Please post a link to a snapshot of your device running this sample application. Much appreciated.

References

is an author and the founder of RubyLearning.com and RubyLearning.org where over 45000 participants, since 2005, have learnt Ruby programming (Basic and Advanced) from across the globe.

Posted by Satish Talim

{ 7 comments… read them below or add one }

Uwe Kubosch March 13, 2013 at 3:30 pm

Great! I have a few comments to the blog:

The ruboto-core gem was renamed to just “ruboto” last year. There is an additional component called RubotoCore which is an APK that you can install on your emulator/device. RubotoCore contains JRuby so you don’t have to include it in every app you make. If you don’t want to use RubotoCore, just generate your app with the “–with-jruby” options. For this you need the “jruby-jars” gem installed.

JDK: You can use any JDK, not just JDK 6. I use Oracle JDK 7, and I will switch to JDK 8 when it is released.

JRuby: You can use any Ruby implementation you like. You can use JRuby as described in your blog, so that part is good. Just for your own education: Any Ruby implementation can be used. We will stop supporting MRI 1.8 when it reaches end-of-life.

All in all, it looks good. Great work!

Note by Satish Talim: Uwe Kubosch has been leading Ruboto and is a Core Developer at Ruboto.

Reply

Satish Talim March 18, 2013 at 4:16 pm

Omar Shariff Delmo (https://www.facebook.com/omaruu) successfully loaded this app on his HTC Sensation. JB 4.2.2

Here’s a screenshot of the app on his mobile – https://www.dropbox.com/s/1vapzmydr9dmwd2/Screenshot_2013-03-18-17-56-00.png

Reply

Random Googler November 2, 2013 at 11:40 pm

If anyone else was getting heap errors during the rake install start part, you might need to add

_JAVA_OPTIONS = -Xmx512M in your system variables. Also, try adding the jrebin in the beginning of your PATH instead of the end.

I spent a long time last night trying to figure out why the step wasn’t working so hopefully this saves you some time.

Also, I kept getting errors once the app was installed because it needed an SD card on the emulator for the Ruboto core apk. You can run this command to create an SD image:

mksdcard -l label size filename

and then run this to launch the emulator with the sdcard:

emulator -avd -sdcard filename.img

Reply

Scott Moyer December 5, 2013 at 9:00 pm

Thanks Satish! Just so readers know: If you want to experiment with Ruboto before setting up a full development environment, you can use the Ruboto IRB app on the Play Store.

https://play.google.com/store/apps/details?id=org.ruboto.irb

You can create and run scripts on the device, or run the demo-irb-server.rb script to run scripts from a remote machine through your browser.

Reply

Phillip March 2, 2014 at 11:00 am

I keep getting this error when running
“ruboto emulator -t android-19″

No emulator is running.
Creating AVD Android_4.4
Error: This platform has more than one ABI. Please specify one.
Valid ABIs: armeabi-v7a, x86
Failed to create AVD.

This is after creating the AVD with the android command. My Google searches for anything Ruboto keep bringing me back here. Any ideas?

Reply

Satish Talim March 2, 2014 at 2:53 pm

Phillip, if you check the GitHub Ruboto issues list – https://github.com/ruboto/ruboto/issues/566 you will notice that the problem you face is an open issue. I’d suggest that you try out one of the the solution listed and also post there whether it worked for you or not.

Reply

Rahul RAUT June 12, 2014 at 12:59 pm

Great Stuff!
I faced issue with the below command. The emulator was not launching after creation.
ruboto emulator -t android-15
The simple bypass was to launch the emulator created above using the AVD Manager.exe
Do have some advance tutorials with ruboto like creating a good UI and connecting with SQLite DB and storing app data.
Deploying without ruboto. Please do share the links.

Thanks a lot!

Reply

Leave a Comment

{ 3 trackbacks }