ruboto - Heurion

scacchicgardenSoftware and s/w Development

Dec 13, 2013 (3 years and 10 months ago)

114 views

Introduction


Ruby on Android


Rhodies


Scripting layer for Android


Rhuboto


Goal of Ruboto


Make Jruby a first class language on Android


Flow of Ruboto


Ruby and Java


Ruboto is a framework for writing full Android
apps in Ruby.


It includes support libraries and generators for
creating projects, classes, tests, and more.


Ruboto expose the complete Android API


we use Java source in a Ruboto project


we add ruby source to a Java Android project


Advantage of Ruboto And JIT


Ruboto project IS an Android Java project. You
can choose which parts of the app you want to
write in Ruby, and which parts you want to write
in Java.



Developing in Ruby allows you a quick
development cycle and more maintainable code


Developing in Java allows for higher
performance.


Right now we have the
dexmaker.jar

based
Dalvik byte code generation which is used for
generating subclasses of Java classes.

Include Jruby


Include the
--
with
-
jruby flag when you create
your app with ruboto gen app


After generating an app you can type ruboto
update jruby
--
force and the two jars will be
included in your libs directory. You will have to
have the jruby
-
jars gem installed in your Ruby
installation.


If you would like to remove JRuby from your
app, just delete libs/jruby
-
*.jar from your project.

JIT and Size


Ruboto not support JIT compilation to Dalvik
byte code


Right now we have the dexmaker.jar based Dalvik
byte code generation which is used for generating
subclasses of Java classes.


A "Hello World" type application (apk) is less
than 40KB. The application installed on the
device is less than 100KB


Ruboto Core platform app installed, which adds
just above 9MB of installed disk space.


Adding the dx library for JIT compilation would
add up to 747KB.

RUBOTO
-
irb


This is a Developer tool for check the code on
devise befor developing app


start demo
-
irb
-
server.rb file


adb forward tcp:8005 tcp:8005


Localhost:8005 on browser

Prerequisites

Platform

JDK

JRuby

ruboto

ant

API level


Gentoo

1.7.0_03

1.6.7

0.5.4

1.8.1

android
-
7

OS X

1.6.0_29

1.7.0.dev

0.5.2.rc.1

1.8.2

android
-
10

Ubuntu 11.10

1.6.0_23

1.6.5

0.5.1

1.8.2

android
-
12

Win7

1.7.0

1.6.4



0.4.0

1.8.2

android
-
13

Ubuntu 10.04

1.6.0_20

1.6.4

0.4.0

1.8.2

android
-
10

OS X

1.6.0_26

1.6.4


0.4.0.rc.4

1.8.2

android
-
10


java&Ant


http://www.oracle.com/technetwork/java/javase/downloads
/index.html


Sudo apt
-
get install ant1.8 (for ubuntu)


http://ant.apache.org/bindownload.cgi


Ruby,Ruby gems and Rake


Use of jruby is optional


gem install ruboto


Gem install rake


Android sdk and plat forms


http://developer.android.com/sdk/index.html


add the sdk's tools/ and platform
-
tools/ directory to your
$PATH


dx

version


android
-
s create avd
-
f
-
n Android_4.1
-
t android
-
16
--
sdcard 64M


emulator
-
avd Android_4.1


Gems:ruboto
-
core & jruby
-
jars


gem install ruboto
-
core


gem install jruby
-
jars

Installations

Generate app


ruboto gen app
--
package
com.yourdomain.whatever
--
path
path/to/where/you/want/the/app
--
name
NameOfApp
--
target android
-
version
--
min
-
sdk
another
-
android
-
version
--
activity
MainActivityName


--
path
--
> Path of app folders to generate


--
name
--
> Name of app ( custom edit)


--
target
--
> Target android version


--
min
-
sdk
--
> minimum sdk supported fotr this app


--
activity
--
> Main activity class name


--
with
-
jruby
--
> includes jruby jars in lib/

Simple button click app

ruboto gen app
--
package com.ruboto.buttonclick

You can see the default folders and files
generated

edit the code on src/buttonclick_activity.rb with the
code

Refer:
-

buttonclick.zip/src/buttonclick_activity.rb


Use of Sqlite Databade app

ruboto
gen app
--
packag
e
com.rub
oto.sqlit
e

You can
see the
default
folders
and files
generat
ed

Create
a new
file
Gemfile
.apk,
and add
the
code

Refer:
-

sqlite.zi
p/Gemfi
le.apk

Configur
e load
path


Create
a new
file
src/conf
ig.rb,
and add
the
code

Refer:
-

sqlite.zi
p/src/co
nfig.rb


Then
add this
line just
below
the top
of
src/sqlit
e_ar_ac
tivity.rb:


require
'config'


Configur
e
databas
e


Create
a new
file
src/andr
oid_log
ger.rb

Refer:
-

sqlite.zi
p/src/an
droid_lo
gger.rb






Use of Sqlite Databade app

Create a new file src/database.rb

Refer:
-

sqlite.zip/src/database.rb

Load the file at the end of src/config.rb

with_large_stack{require 'database'}

Create a new file src/migrate.rb


MIGRATION_PATH =
File.expand_path("#{SRC_DIR}/migrate")

puts "Looking for migration scripts in
#{MIGRATION_PATH}"

migrator = ActiveRecord::Migrator.new(:up,
MIGRATION_PATH)

if migrator.pending_migrations.size > 0


puts "Found #{migrator.pending_migrations.size}
migrations."


migrator.migrate

End


Load the file at the end of src/config.rb

with_large_stack{require 'migrate'}


Use of Sqlite Databade app

Create a new file in
src/migrate/001_create_people.rb

Refer:
-

sqlite.zip/src/migrate/001_create_people.r
b

Add data and display table


Create a new file src/person.rb

class Person < ActiveRecord::Base


validates_presence_of :name


validates_uniqueness_of :name

End


Use of Sqlite Databade app

Edit src/sqlite_ar_activity.rb to

Refer:
-

sqlite.zip/src/sqlite_ar_activity.rb

Spy cam App

ruboto gen app
--
package com.ruboto.spycam

You can see the default folders and files
generated

Add a new file src/spycam_server.rb:

Refer:
-

spycam.zip/src/spycam_server.rb

Add permissions

Add the following lines to you
AndroidManifest.xml file, just after the
uses_sdk tag:



<uses
-
permission
android:name="android.permission.CAME
RA"/>


<uses
-
permission
android:name="android.permission.INTER
NET"/>


<uses
-
permission
android:name="android.permission.ACCE
SS_WIFI_STATE" />


<uses
-
feature
android:name="android.hardware.camera"/
>


<uses
-
feature
android:name="android.hardware.camera.
autofocus"/>

Refer:
-

spycam.zip/AndroidManifest.xml

Spy cam App

Activate the web server

Edit src/spycam_activity.rb to this:

Refer:
-

spycam.zip/src/spycam_activity.rb

Take a picture

Add a new file src/camera_helper.rb:

Refer:
-

spycam.zip/src/camera_helper.rb

Ater Deploy app with command from root
directry

Rake install

The app should restart and show two lines of
information:


Server: WEBrick started on
http://xxx.xxx.xxx.xxx:4567/

Picture:

Point a web browser to the given URL. You
should get a web page with a picture from
the camera. Click the camera to update the
picture.

Issues


Issues


Startup sppd


Stack limits


Appsize


Compiling Ruby


Generating Byte code


Limitations


Mobile hardware Limitations(Memory Stack
limit)


Delvik VM (jar include)


Requesting control from java


Jruby exes components


Android resourrce framework(Losing Dynamic
programing)