-
15 Apr
New in RubyMotion for Android: Automatic Setup, RubyMine, Intel Architecture, Gradle, Improvements
Since we launched support for the Android platform in December there has been a lot of development in this area, and we would like to take the opportunity to highlight important changes.
Automatic setup of Android environment
To get started with RubyMotion for Android, a proper Android environment is needed, and we used to ask users to download and setup numerous components by themselves.
We now provide a single command that will automatically download and setup all the required components for you:
$ motion android-setup
The command will download the Android SDK and NDK, configure RubyMotion to use them, then run the Android UI to let you select versions of Android you want to develop for.
RubyMotion supports all versions of Android covered by the SDK, including the very latest API 22 (Android 5.1).
RubyMine supports RubyMotion for Android
Our friends at JetBrains are providing RubyMotion for Android support in RubyMine as part of the Satsuki Early Access Program.
You can now enjoy intelligent code-completion and toolchain integration when writing Android apps in RubyMine.
These are early-access builds, please keep in touch with JetBrains if you are running into issues.
Multi-architecture support, Intel, Genymotion
RubyMotion for Android projects can now be built for multiple architectures instead of one. Previously-supported architectures were
armv5te
andarmv7
, and we now supportx86
(Intel 32-bit) as well.You can specify the architectures you need by changing the
app.archs
setting in theRakefile
of your project:Motion::Project::App.setup do |app| ... app.archs = ['armv5s', 'x86'] end
Intel support is not enabled by default, but can be added if you want to use a faster emulator. The built-in Android emulator is notoriously slow, but 3rd-party products such as Genymotion provide faster alternatives.
To use Genymotion with RubyMotion for Android projects, you simply need to download it (it's free for personal use), then create a virtual device, and make sure it is launched. After that, configure your RubyMotion project to build for the
x86
architecture, and use the defaultrake
task which will talk to the default Android emulator.$ rake emulator $ rake # shortcut for 'rake emulator'
The application will show up immediately in the Genymotion device and the interactive console (REPL) will also be connected to it.
3rd-party Java dependencies with Gradle
Gradle is an advanced build tool that can be used to manage 3rd-party dependencies in a Java-based project. As it seems to be highly popular in the Android world we decided to abstract this functionality into a RubyMotion gem: motion-gradle.
motion-gradle lets you easily describe 3rd-party Java dependencies in your app, similar to motion-cocoapods in an iOS project.
In order to use it, you need to install Gradle first (you can do this via homebrew) and make sure the
gradle
executable is in your$PATH
. You also have to add themotion-gradle
gem in theGemfile
of your project.The gem exposes a new API to define dependencies, following is an example:
Motion::Project::App.setup do |app| # ... app.gradle do dependency 'com.mcxiaoke.volley', :artifact => 'library', :version => '1.0.10' dependency 'commons-cli' dependency 'ehcache', :version => '1.2.3' end end
After that, you can run the
gradle:install
task which will download the required dependencies from the main Gradle repository and make sure they are properly vendored in the build system of the RubyMotion project:$ rake gradle:install
After this command, all the Java APIs in these libraries should be available from your Ruby code.
Build system improvements
We extended the Rakefile project configuration object with the following settings:
app.manifest
: a special object that will be used to create theAndroidManifest.xml
file during the build. You can configure the entire manifest from there. More information on the Project Management Guide.app.optional_features
: same asapp.features
except that they will be exported as optional in the manifest file. This could for instance be used when your app may require camera access, if it is available.
app.optional_features << 'android.hardware.camera'
app.support_libraries
: a convenience way to specify the Android support libraries to be included in your app, instead of manually vendoring them.
app.support_libraries << 'google-play-services' app.support_libraries << 'android-support-v4'
app.theme
: lets you set the theme of the app. The default value isTheme.Holo
.
app.theme = 'Theme.Holo.Light'
Also, Bundler is now integrated in new projects. Dependencies can be added to the
Gemfile
as usual.Finally, we improved the build system to make builds faster. Ruby files are now compiled in parallel jobs, exactly as in iOS and OS X projects, and the link phase (when generating the machine code library) was also shortened.
Despite these features and improvements, the Android support of RubyMotion is still in active development, compared to the more stable iOS version. We are fully committed in supporting Android and we will keep releasing builds on a monthly basis, which we have done since we publicly launched it in December.
Interesting in meeting the RubyMotion community and also discovering future directions of the product? Join us the 1st and 2nd July in Paris, France for our annual developer conference. Grab your ticket today!