Talks
Ruby on Android
Summarized using AI

Ruby on Android

by Nick Howard

Ruby on Android

In this video, Nick Howard discusses the integration of Ruby and Ruby-like tools within the Android development environment during the Rocky Mountain Ruby 2012 event.

Key Points:

  • Setting Up Ruby on Android:

    • To start using Ruby on Android, one must first install the Android SDK, which allows for the running of an emulator and packaging apps.
    • A tool named Roboto, a modified version of JRuby for Android, enables the creation of Ruby applications.
  • Use of Gems:

    • Developers need to install a specific gem that manages the build process. This gem does not run tests but packages JRuby with the application to target specific Android versions and packages.
  • Android Activities:

    • An Android app is composed of activities, which can be likened to web app pages, containing elements like buttons.
    • A basic example involves an activity displaying “Mr. Roboto” and including a button to change text.
  • Introduction to Mirro:

    • Mirro, another project mentioned, compiles directly to JVM bytecode, resembling Ruby but using Java’s object model.
    • Mirro simplifies coding with a framework to create Android applications; developers provide type information for the compiler to better understand the code.
  • Example Projects:

    • Nick illustrates how to create an Android game app. For example, a Sudoku game and a simple game called Guess My Number, where players guess a randomly generated number with hints provided upon their guesses.
  • User Interface Development:

    • While the UI developed using these tools may not match RubyMotion's polish, there is a DSL available for UI building.
    • He mentions an app that allows running Ruby code on Android devices, along with an IRB app for on-the-go calculations.

Conclusion:

This session highlights how Ruby can be adapted for Android development through tools like Roboto and Mirro, demonstrating that developers can utilize familiar Ruby syntax while addressing platform-specific requirements. Nick provides insights into creating functional apps and encourages experimentation with Ruby on Android tools while considering their advantages and constraints.

00:00:06.680 All right, so I want to talk about Ruby and Ruby-like tools for Android. The first thing we need to address is how to get Ruby running on Android. Well, not exactly Ruby; we don't start with Ruby, because first, you have to install the Android SDK. That needs to be available so that you can run an emulator and build packages.
00:00:12.360 You need to do that first, but then you can use a tool called Roboto, which is a modified version of JRuby that runs on Android. This is really cool! If you want to create an app using that, you first need to install the gem. I think the gem can actually be installed on MRI because it essentially controls the build process.
00:00:21.600 The gem itself doesn't necessarily run your tests; it packages JRuby with your application, so you can generate an app using a command that specifies the version of Android you want to target, using the Android IDs provided. You will also need to specify the package name, as it still operates within the Java environment.
00:00:32.399 This generates a whole bunch of files. I was going to show you the basic activity example that it generates, which can be quite verbose. So, Android has a concept of an activity, which is similar to a page on a web app—it has buttons and other elements.
00:00:39.000 The default activity simply displays "Mr. Roboto" as the title and includes a button that changes some text when pressed. While this may not be particularly interesting, it gives you a basic idea of how to modify things. The initialize method behaves a bit differently on Android due to the object creation process.
00:00:48.320 Now, let's talk about Ruby's role in all of this. There's also a project called Mirro, which is similar to Ruby but compiles directly to JVM bytecode and uses Java's object model. It resembles Ruby but differs in many ways. It also has a framework for writing Android applications.
00:00:55.120 With that, you run a similar command to generate the necessary framework for your project. The code for projects using Mirro looks simpler, as shown in some example code I have.
00:01:04.320 For instance, one example is an Android tutorial that walks you through creating a Sudoku game app. Just like the previous activity examples, in the onCreate method, you set up the state and listeners for the various components within your app.
00:01:22.840 You will respond to different events, and the code typically resembles Ruby syntax. However, with Mirro, you will need to include some type information for the compiler to understand the types of objects you are using.
00:01:34.480 If you inherit from existing classes, the compiler can infer the types more easily. This simplifies the coding process, which is pretty cool.
00:01:43.360 I wrote a little test app called Guess My Number, which is a simple game. The game creates a random number and allows you to keep guessing it while tracking the number of attempts. You can ask the game for advice, and it will compare your last guess to the target number, letting you know whether you won or lost.
00:02:06.360 I created an activity for this app; unfortunately, I don't have an emulator running right now, but if I did, I would show you how it works. You can click a button to make a guess and fill in a text field.
00:02:15.280 The user interface isn't as polished as those created with RubyMotion. However, there is a fairly nice DSL for building UIs.
00:02:21.680 You can download an app from the App Store that allows you to run Ruby code on your phone. There's even an IRB app for performing calculations on the go, which is pretty neat!
00:02:29.040 Anyway, thanks for listening!
Explore all talks recorded at Rocky Mountain Ruby 2012
+12