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!
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
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
To test that JRuby is working, in a new command window type:
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.
To install ruboto, in a new command window type:
jruby -S gem install ruboto
Now close the command window.
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
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.
Make sure you can run the Ant command.
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:
Next set the system environment variable
ANDROID_HOME=D:\Android\android-sdk Add the following to the system environment variable
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
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:
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
--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:
- Locate the Android SDK build-tools directory being used by Ruboto. For me, this directory is located at
- Open the
dx.batfile in your preferred text editor.
- On line 53 of
dx.bat, copy the
set defaultXmxline modified by Ruboto and paste it below on line 54.
- Change the pasted value on line 54 from
2048Mto the original
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:
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:
Single-click on this and you should see:
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:
Our sample application can now be executed. Click on the Click Me button and you should see a final screen as shown:
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.
Satish Talim 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.