MountainWest RubyConf 2011

Summarized using AI

Ruby on Android

Joe O'Brien • February 18, 2015 • Earth

In the presentation titled Ruby on Android by Joe O'Brien at the MountainWest RubyConf 2011, the speaker explores the integration of Ruby with the Android platform using JRuby. He shares his personal journey in learning Android development, transitioning from traditional Java methods to a Ruby-centric approach, facilitated by JRuby. Throughout the talk, O'Brien highlights several key aspects of Android development, emphasizing how Ruby can simplify and enhance the process.

Key Points Discussed:

- Introduction to Android Development:

- Android, an operating system by Google, traditionally relies on Java, which is complex and bulky.

- O'Brien compares his experiences with Android development to that of iOS, finding Android's environment more pleasant.

  • Development Environment Setup:

    • Setting up the Android development environment involves downloading packages and utilizing virtual devices for testing.
    • He discusses the challenge of replicating actual device specifications with virtual machines.
  • Tools and Frameworks:

    • Most documentation favors using Eclipse; however, O'Brien argues for alternatives like the Android Debug Bridge (ADB) for command-line interaction, which simplifies the development process.
    • He emphasizes the importance of understanding the Dalvik virtual machine, Android's runtime environment for apps.
  • Understanding Android Architecture:

    • O'Brien explains Android's fundamental components like activities (controller for UI), broadcast receivers (event listeners), and content providers (data management).
    • He recommends starting with Java to grasp these concepts before diving into Ruby.
  • JRuby's Role in Android Development:

    • JRuby, built on the Java Virtual Machine, facilitates Ruby development for Android, despite its own set of challenges.
    • O'Brien introduces the Roboto library, which simplifies JRuby usage by generating boilerplate code that conforms to Java's structure.
  • Development Challenges and Solutions:

    • O'Brien discusses issues encountered while managing global variables and suggests looking into the Pinda library for better performance and testing.
    • He shares an anecdote about developing an application called Garrett to experiment with JRuby on Android, highlighting trial and error in the learning process.
  • Conclusion and Resources:

    • He encourages deeper exploration of the JRuby community and resources available for Android development, emphasizing that while complexities exist, support is available through community projects.
    • O'Brien concludes with responses to audience questions, addressing common issues and encouraging ongoing collaboration.

Ruby on Android
Joe O'Brien • February 18, 2015 • Earth

By, Joe O'Brien
With the advent of JRuby many doors have been opened that were not before for Ruby. One particular place is the android platform. Using Ruby, we can easily leverage the Android platform and API's to create incredible applications. Since we are using Ruby, testing becomes a trivial exercise. I'll walk through the options we have for developing full feature-rich applications for both the Android tablet and the phone. I'll show how we can use JRuby to sidestep the complexity and configuration-heavy frameworks that are traditionally for Android development.

Help us caption & translate this video!

http://amara.org/v/GJEv/

MountainWest RubyConf 2011

00:00:15.120 Before I dive into the topic, I have a little funny story to share. I've been a speaker for quite some time, and I often submit talks on subjects I'm passionate about. Occasionally, I include one or two talks on topics I want to learn more about. Music is one of my favorite interests, and I decided I wanted to get into Android development. I spoke with my band about developing an Android app for them, considering we already have an iPhone app, and I thought it would be a fun project. I submitted a proposal to a conference in Ohio, listing various potential talks, one of which was on Ruby and Android. Having looked into the available libraries and watched some previous talks, about three weeks before the conference, I sat down to start experimenting with it.
00:00:40.320 As the proposal discussions for this conference came up, along with others, I suddenly had to combine a couple of abstracts. Unfortunately for me, as I started working with the library, I realized just how much I disliked it. I struggled and almost gave up the night before my talk. In a fit of desperation, I googled 'Ruby and Android' one more time and stumbled upon something that saved my day and reignited my passion for the project.
00:01:03.760 Although I wasn’t prepared with slides—since I've literally been hacking on this library for the last ten minutes—I’ve got a lot to share. This talk is a moving target, which is kind of exciting. Now, how many of you have experience with Android development?
00:01:21.040 For those who haven’t worked with it yet, I'd like to go through the metaphor of Android's development environment and explain what it entails. Android is an operating system for phones and tablets developed by Google. It uses Java, but Google has created its own Java Development Kit (JDK) because the standard version is enormous and overly complex for their needs. They stripped out much of the unnecessary bulk to get closer to the hardware and take advantage of the underlying Unix architecture.
00:01:51.439 My experience with Android development has actually been quite enjoyable. A friend of mine once said that Android is going to be the Windows of the mobile market. While it might be less responsive, uglier, and not as user-friendly, it's growing rapidly and gaining market share. When it comes to development, the environment is remarkably pleasant, especially compared to my time with iOS development.
00:02:04.640 Setting up Android is simple; you just download the necessary components and have an interface that allows you to download the required packages. You’ll find numerous devices to develop for, which makes it essential to get as many of the SDKs as possible. It's ironic, however, that Google is listed as a third-party add-on even though they developed the resources available.
00:02:29.920 After installing the necessary packages and SDKs, you can work with virtual devices, which are essentially virtual machines that run your Android projects. These emulators are surprisingly efficient and allow for a smooth workflow during the development process. In fact, I found myself upgrading my RAM and getting an SSD just to handle Android development better.
00:02:58.880 Now, when creating virtual devices, I still encounter the challenge of reproducing the specifications of an actual device I'm holding in my hand. I find it amusing that even though I have the device information, it's easier to refer to external sources to get the specs right. Furthermore, every virtual device you create can use the emulator features like rotation and the on-screen keyboard, which makes for an interactive experience.
00:03:35.440 You will notice that most Android development documentation is heavily centered around Eclipse. Most authors recommend using it due to its template generators, but I would argue that you don't have to use Eclipse at all. While it has its merits, it's often slow and cumbersome. In reality, you can effectively develop without it, using the Android Debug Bridge (ADB) instead. This command-line tool offers an extensive solution for managing your Android device environment.
00:04:11.280 With tools like ADB and the Android virtual simulator, combined with a text editor, developing is as straightforward as installing Ruby on Rails. You can explore various commands once you set everything up. An amusing command to play around with is accessing a shell on your Android phone, since, technically, it operates as a Unix-like device. This allows you to navigate through files and examine processes that are running in real-time.
00:04:40.320 You can also interact with the device logs and visualize everything happening within your app. An essential aspect of Android development is the Dalvik virtual machine, which is specifically designed to run Android applications. While the original Java Development Kit (JDK) is rich in features, it does lack some aspects necessary for Android, such as reflection capabilities. This is a crucial part of the development process as we work with items like J-rooms.
00:05:10.720 Among the various components needed for Android development are activities, which act like the controllers behind your layouts. Activities receive inputs and handle processes in the background. If you're familiar with apps like Pandora, the app's activity might not only manage the visual display of what’s going on, but it also connects to the server to play music. This multitasking capability allows users to navigate between apps while maintaining functionality.
00:05:44.240 You also have broadcast receivers, which can be viewed like topics that listen for messages from the system. Think of it as a notification system where your app registers for specific events, such as receiving SMS messages. Likewise, content providers manage your data layers, whether it's an SQLite database or pulling information from a REST service. These components create a cohesive application experience.
00:06:15.920 I encourage everyone who's interested to explore the extensive documentation available at developer.android.com. If you're aiming to do Android development, I recommend starting with a simple Java application to familiarize yourself with the environment, as most documentation will be written in that form. While Java may not be the most exciting language, it's crucial to understand how Android operates under the hood.
00:06:50.080 Now we circle back to JRuby, which sits on top of the JVM. While JRuby offers a complete Ruby implementation, the journey of using it on Android brings its own set of challenges. The Dalvik virtual machine caused certain issues because traditional Java programming doesn’t leverage reflection extensively. However, JRuby heavily relies on it, which brought complications in Android's context.
00:07:38.639 To that end, when there was a call for a summer project, contributors raised funding to support the development of JRuby on Android. This led to an initiative where a high school student was able to work on it, giving birth to a library called Roboto. They managed to create a tool where developers could use JRuby effectively on the Android platform.
00:08:21.679 For instance, there’s a command line tool that helps generate boilerplate code for your applications using Roboto. It sets up various structures to help manage source code in a manner consistent with Java conventions. Assets and their properties must also be defined accordingly, especially if you use the standard Java packaging structure, which reflects in your folder hierarchy.
00:09:12.480 Using Roboto can be extremely beneficial for Ruby developers looking to dive into Android development. It simplifies some of the complexities that arise when working directly with Java and allows you to structure your Ruby code intuitively. In Roboto, you’ll find activities defined as classes, and even though they are reminiscent of Java, you have the Ruby flavor throughout.
00:09:54.560 However, we also need to address the issues that come with adopting this architecture. One challenge includes working with global variables, which can make structure testing quite difficult. This makes testing harder since the scope of these variables is large, complicating the testing harness. Thus, managing states and implementations of interfaces presents hurdles you need to overcome.
00:10:38.240 Through trial and improvement, I stumbled upon an application called Garrett, which serves as a test application for experimenting with combining Ruby's Mirage on Android. Previously, this project was attempting to add optional typing to JRuby for better performance and ease of use. The library called Pinda emerged as a descendant of this initiative, making implementing these features more straightforward and efficient.
00:11:28.319 The Pinda library allows for the seamless generation of applications, encapsulating many features designed to streamline your development. The tools provided help mimic the Java structure while still allowing developers to use Ruby syntax and conventions without the added complexity associated with traditional Java frameworks.
00:12:17.760 When deploying the applications, it’s essential to ensure that the setup translates into a functional app running on an Android device. The deployment speed is generally faster compared to previous libraries due to how JRuby optimizes the process, stripping out unnecessary libraries and reducing overhead significantly.
00:13:07.200 As I worked towards building a simple application, I realized that many of the methods still adhered closely to their Java counterparts. By implementing class-level methods and getting rid of boilerplate code, I aimed to create a more streamlined and ‘Ruby-like’ coding experience. This process has proven challenging but ultimately rewarding as you balance the intricacies of Android's operational structure with Ruby’s flexibility.
00:14:23.919 One of the things I’ve been developing is a DSL (Domain-Specific Language) styled similarly to Cocoa, which can minimize XML usage in Android development. The exploration of this meta-programming concept highlights the adaptation difficulties while introducing features typically found in Ruby. However, the outcomes inspire me to continue improving the setup with practical examples.
00:15:50.240 As we wrap things up, there's a plethora of resources available that can help you dive deeper into JRuby and Android development. The journey involves navigating through some complexities, but communities like the one on GitHub for Mira and Pinda encourage collaboration and exploration. I encourage you to immerse yourselves in these projects and experiment with your applications.
00:16:37.439 Thank you for your time! If you have any questions, I’ll be happy to take them now.
00:17:02.560 One question I've received is regarding the 'R' file issue, which indeed has historically been a pain point. Pinda does address this, where R files help manage resource references smoothly. This means interaction with resources has been simplified, making for a more coherent development experience.
00:17:43.920 Another common inquiry relates to runtime size in comparison with JavaScript implementations. The runtimes were significant, but Pinda's setup reduces much of that overhead, enabling a more efficient build process while still retaining the Ruby flavor that many of us appreciate.
00:18:08.480 The startup time of the Android emulators can also be quite lengthy, particularly for the first launch. However, subsequent uses can reflect improved responsiveness, especially when running off solid-state drives. Many developers have noted discrepancies between different libraries concerning load speeds.
00:19:06.560 Feel free to reach out afterwards if there are any further questions or discussions you'd like to have. Thank you for attending, and I hope you join in with the Android and JRuby community!
Explore all talks recorded at MountainWest RubyConf 2011
+13