Giter Site home page Giter Site logo

ruboto's Introduction

Ruboto 2

Ruboto 2 is a redesign based on an Android Studio workflow. This means that the JRuby and Ruboto components will integrate into the standard gradle tooling used by regular Android Studio projects.

Starting a new Ruboto project

  • Download and install Android studio.

  • Choose "Create New Project" in the startup screen.

    • Choose "Phone and Tablet" and "No Activity" for the project template.
    • Choose "Java" for your language and "Minimum SDK" should be "API 27: Android 8.1 (Oreo)" or higher.
  • Add a jcenter to the dependencyResolutionManagement/repositories section of your settings.gradle file:

    dependencyResolutionManagement {
        ...
        repositories {
            ...
            jcenter()
        }
    }
  • Add the these dependencies to your app/build.gradle file:

    dependencies {
      ...
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.linkedin.dexmaker:dexmaker:2.19.1'
      implementation 'me.qmx.jitescript:jitescript:0.4.1'
      implementation 'com.jakewharton.android.repackaged:dalvik-dx:7.1.0_r7'
    }
  • Add gems.rb file:

    source 'https://rubygems.org/'
    
    gem 'ruboto', '~>2.0.dev', git: 'https://github.com/ruboto/ruboto.git'
  • Ensure you are using JRuby on the command line

    Create a .ruby-version file:

      jruby
    
  • Initialize Ruboto:

    jruby -S bundle
    jruby -S bundle exec ruboto init

    This will copy the core files to your project.

  • Add app/gems.rb

    source 'https://rubygems.org/'
    
    gem 'activerecord', '~>7.0'
    gem 'activerecord-jdbc-adapter', '~>70.1'
    gem 'sqldroid', '~>1.0'
  • Add app/update_jruby_jar.sh:

    #!/usr/bin/env bash
    set -e
    
    VERSION="9.4.2.0"
    FULL_VERSION="${VERSION}"
    # FULL_VERSION="${VERSION}-SNAPSHOT" # Uncomment to use a local snapshot
    # FULL_VERSION="${VERSION}-20190822.050313-17" # Uncomment to use a remote snapshot
    JAR_FILE="jruby-complete-${FULL_VERSION}.jar"
    DOWNLOAD_DIR="$HOME/Downloads"
    DOWNLOADED_JAR="${DOWNLOAD_DIR}/${JAR_FILE}"
    SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
    
    cd $SCRIPT_DIR
    
    [ ! -d $HOME/Downloads ] && mkdir $HOME/Downloads  # Create the directory if we don't find it
    [ ! -d ./libs ] && mkdir ./libs                    # Create the directory if we don't find it
    
    cd libs
    rm -f bcpkix-jdk15on-*.jar bcprov-jdk15on-*.jar bctls-jdk15on-*.jar cparse-jruby.jar generator.jar jline-*.jar jopenssl.jar jruby-complete-*.jar parser.jar psych.jar readline.jar snakeyaml-*.jar
    
    if test -f "${DOWNLOADED_JAR}"; then
      echo "Found downloaded JAR"
    else
      echo No "${DOWNLOADED_JAR}" - Downloading.
      curl "https://oss.sonatype.org/service/local/repositories/releases/content/org/jruby/jruby-complete/${VERSION}/jruby-complete-${VERSION}.jar" -o "${DOWNLOADED_JAR}"
    fi
    cp ${DOWNLOADED_JAR} .
    
    unzip -o -j ${JAR_FILE} '*.jar'
    
    # FIXME(uwe): Why do we delete these files?
    zip generator.jar -d json/ext/ByteListTranscoder.class
    zip generator.jar -d json/ext/OptionsReader.class
    zip generator.jar -d json/ext/Utils.class
    zip generator.jar -d json/ext/RuntimeInfo.class
    
    cd - >/dev/null
    
    cd src/main/java
    find * -type f | grep "org/jruby/" | sed -e 's/\.java//g' | sort > ../../../overridden_classes.txt
    cd - >/dev/null
    
    while read p; do
      unzip -Z1 libs/${JAR_FILE} | grep "$p\\.class" > classes.txt
      unzip -Z1 libs/${JAR_FILE} | egrep "$p(\\\$[^$]+)*\\.class" >> classes.txt
      if [[ -s classes.txt ]] ; then
        zip -d -@ libs/${JAR_FILE} <classes.txt
        if [[ ! "$?" == "0" ]] ; then
          zip -d libs/${JAR_FILE} "$p\\.class"
        fi
      fi
      rm classes.txt
    done < overridden_classes.txt
    
    rm overridden_classes.txt
    
    cd libs
    rm -f digest.jar
    cd - >/dev/null
  • Make app/update_jruby_jar.sh executable:

      chmod u+x app/update_jruby_jar.sh
  • Generate jruby.jar:

      app/update_jruby_jar.sh
  • Generate the startup activity:

      bundle exec ruboto gen class Activity --name StartupActivity
  • Add the startup activity intent filter to the new activity tag in app/src/main/AndroidManifest.xml:

    <activity android:name='StartupActivity' android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.VIEW" />
        </intent-filter>
    </activity>
  • Declare the Ruboto components and SplashActivity in app/src/main/AndroidManifest.xml

    <activity android:name='org.ruboto.RubotoActivity' />
    <activity android:name='org.ruboto.RubotoDialog' android:theme='@android:style/Theme.Dialog' />
    <service
        android:name='org.ruboto.RubotoService'
        android:exported='false' />
    <activity
        android:name='org.ruboto.SplashActivity'
        android:configChanges='orientation|screenSize'
        android:exported='false'
        android:noHistory='true' />

    Rember to sync the gradle config after the changes.

  • Start your app!

Updating app gems

Update your app/gems.rb (or app/Gemfile) and run

bundle exec rake bundle

Adding Ruboto to an existing Android Studio project

HOWTO missing. Pull requests welcome!

Ruboto 1.x

Looking for Ruboto 1.x? Switch to the ruboto_1.x branch.

ruboto's People

Contributors

anupcowkur avatar atomicpair avatar banzaiman avatar captainjet avatar danielpassos avatar donv avatar douglasdollars avatar elcubo avatar gfowley avatar headius avatar ifiht avatar jackowayed avatar javiyu avatar jberkel avatar jludvice avatar kentonwhite avatar kjperry avatar lucasallan avatar lucianopc avatar maddijoyce avatar mcandre avatar messivanio avatar michael-zinn avatar mseymour avatar nyangawa avatar passion8 avatar rgs1 avatar rscottm avatar sardaukar avatar uwekubosch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruboto's Issues

Splash Screen

It would be nice if there were something that indicated that the app was loading while JRuby gets initialized. Even better would be an image splash screen, which I think is something the iPhone SDK does.

do custom jar's get deleted?

Hi there,

I'm trying to require some jars in my script but it looks like they get deleted somehow during processing.
The jars still exist in the compiled apk file where I placed them, but it seems they are getting deleted when running the emulator. I get a file not found error when require the jar.
Because I'm unexperienced with android , having no idea how to browse the system, I've written a small bugy browser to check the working directory, looks like this:

require 'ruboto.rb'
ruboto_import_widgets :ListView, :LinearLayout, :TextView

$activity.handle_create do |bundle|
@current=Dir.getwd
@list=Dir.entries(Dir.getwd)
setTitle 'File Browser'
setup_content do
linear_layout :orientation => LinearLayout::VERTICAL do
@text_view = text_view :text => @current
   @list_view = list_view :id => 55557, :list => @list
end
end
handle_click do |view|    
  action_ls if view.getText == 'ls'
end
handle_item_click do |adapter_view, view, pos, item_id|
 if @list[pos].to_s=='..' || @list[pos].to_s=='.'
   action_back
else
  Dir.chdir(Dir.getwd+'/'+@list[pos])
  action_ls
end
end
end

def action_back
  Dir.chdir("../")
  action_ls
end
def action_ls
  @list = Dir.entries(Dir.getwd)
  @list_view.reload_list(@list)
  @text_view.text=Dir.getwd
end

The odd thing here is it doesn't show all the directories when jumping a directory back. Any idea ?

Release 0.1.0 gem

This is a placeholder issue to keep the 0.1.0 milestone open until we have placed all the old issues on it.

OpenGl Demo , rake update_scripts no effect

Hi !
I tried out the OpenGl Demo with your new version 6, it works fine but

  • I had to place the Cube class before the main loop, otherwise i would get a error that it's not available
  • It seems like the rake task update_scripts doesn't work anymore, the script remains the same.Could you check if it works for you ? If yes I obviously broke something else...

I'm on
emulator API Level 8, Platform 2.2

kind regards
Peter

cannot generate app

consistently get this directory create error with jruby 1.5.2 and 1.6.0

and if I create the directory it complains that it already exists, well - what are the curious to do?

andy@hst-26-147->ruboto gen app --package com.blah.ruboto --path fishmonger --name Fishmonger --target android-8 --activity Fishmonger

Generating Android app Fishmonger in /Users/andy/fishmonger...F, [2011-03-28T14:30:50.983000 #14473] FATAL -- : No such file or directory - No such file or directory - fishmonger (Errno::ENOENT)
/Users/andy/.rvm/gems/jruby-1.5.2/gems/ruboto-core-0.1.0/lib/ruboto/commands/base.rb:70:in chdir' /Users/andy/.rvm/gems/jruby-1.5.2/gems/ruboto-core-0.1.0/lib/ruboto/commands/base.rb:70:inrun'
/Users/andy/.rvm/gems/jruby-1.5.2/gems/main-4.2.0/lib/main/program/class_methods.rb:147:in run' /Users/andy/.rvm/gems/jruby-1.5.2/gems/main-4.2.0/lib/main/program/class_methods.rb:135:incatch'
/Users/andy/.rvm/gems/jruby-1.5.2/gems/main-4.2.0/lib/main/program/class_methods.rb:135:in run' /Users/andy/.rvm/gems/jruby-1.5.2/gems/main-4.2.0/lib/main/factories.rb:18:inrun'
/Users/andy/.rvm/gems/jruby-1.5.2/gems/main-4.2.0/lib/main/factories.rb:25:in Main' /Users/andy/.rvm/gems/jruby-1.5.2/gems/ruboto-core-0.1.0/lib/ruboto/commands/base.rb:21:inmain'
/Users/andy/.rvm/gems/jruby-1.5.2/gems/ruboto-core-0.1.0/bin/ruboto:5
/Users/andy/.rvm/gems/jruby-1.5.2/gems/ruboto-core-0.1.0/bin/ruboto:19:in `load'
/Users/andy/.rvm/gems/jruby-1.5.2/bin/ruboto:19

Release 0.2.0 gem

This is a marker issue to keep the 0.2.0 milestone open until actually released.

GitHub closes and disables the milestone immediately when the last open issue is closed.

Upgrading scripts when app updates

Right now the scripts only upgrade (copied from assets) when the scripts directory is initially created in the /data directory. To get them to upgrade you need to either uninstall or clear the user data. We need a better way to force an upgrade

Remove error messages from startup: Could not find class

At startup of every ruboto-core app we see messages like this:

E/dalvikvm(27340): Could not find class 'sun.misc.Signal', referenced from method org.jruby.util.SunSignalFacade.trap
E/dalvikvm(27340): Could not find class 'org.jruby.util.SunSignalFacade$JRubySignalHandler', referenced from method org.jruby.util.SunSignalFacade.trap
E/dalvikvm(27340): Could not find class 'org.jruby.util.SunSignalFacade$JRubySignalHandler', referenced from method org.jruby.util.SunSignalFacade.trap
E/dalvikvm(27340): Could not find class 'com.kenai.jnr.x86asm.Assembler', referenced from method com.kenai.jaffl.provider.jffi.StubCompiler.hasAssembler

These can probably be removed.

Add output for ruboto gen class

ruboto gen class currently does its thing with zero feedback. At first I thought it wasn't doing anything. We should at least print what files are being created.

non-root device problem

i think there's a problem running in a non-root phone ..
I'm getting "W/System.err(12763): java.io.FileNotFoundException: /data/data/org.rubyonlinux.scale/files/scripts/hello.rb" when I try to run my hello_world on a non-rooted device when the app attempts to startup .. but works ok in the emulator. Is it possible it's not copying the scripts properly? I can't adb shell over to that directory cause of perms.

update ruboto

hello,
I've done
ruboto update ruboto
but nothing happens instead of this:

  Ruboto -- Ruby for Android
  Execute `ruboto gen app 

I expected a fresh ruboto.rb , am I missing something here ?

Release 0.3.0 gem

This is a marker issue to keep the milestone open until it is actually released.

Add "android" as recognized top-level package

Allow writing

android.app.Activity

instead of

Java::android.app.Activity

The main purpose is for me (donV / Uwe Kubosch) to get involved in the project and to indicate that on the Ruboto platform the "android" package is a first class citizen equal to com, org, java, and javax.

First thought on implementation is to add this to ruboto.rb just below require 'java'

class Object
  def self.android
    Java::android
  end

  def android
    self.class.android
  end
end

Comments are welcome.

rake update_scripts has no visible effect unless Activity destroyed...

rake update_scripts seemed to have no effect- just found that when pressing Back on the emulator to exit the Ruboto activity, then re-running the .apk, Activity.onCreate() wasn't being called because the old activity was merely being resumed, not re-created. The result was that the updated .rb files were never reloaded.

Adding this to MyRubotoActivity.java should force the Activity to exit when Back is pressed:
public void onPause() {this.finish(); super.onPause();}

...but the generated activity probably shouldn't do that by default. It might be desirable to simply mention this in the update_scripts documentation.

Only re-dex class files if class files have changed

Currently every time you build "debug" or "release" apk from a ruboto-core project, it re-dexes all of JRuby and your app's Java code. That's obviously unnecessary if the app's logic is mostly in Ruby.

update_scripts helps a lot, of course, but it would be nice if you could just build .apk files without re-dexing stuff that hasn't changed. It would also avoid the confusing situation where an app has been re-built and re-installed, but the scripts have not been updated.

We should have dexing happen as a separate step, dependent on whether the libs jars and the app's .java/.class files have actually changed. If they have not, the existing dex file can be used. This would greatly speed up the build/deploy/test cycle for Ruboto apps.

assets/scripts/ruboto.rb is confusing.

L33:

module Ruboto
  java_import "#{$package_name}.R"
  begin
    Id = JavaUtilities.get_proxy_class("#{$package_name}.R$id")
  rescue NameError
    Java::android.util.Log.d "RUBOTO", "no R$id"
  end
end

I think is better to delete "module Ruboto", because it didnot define any method in Ruboto Module
, When this file is requried, the codes is just ran.

Ruby stdlib not making it to the device

We're going to need a rake task to convert the jruby-stdlib-1.X.X.jar into a format that makes it to the device. The default jar has them in META-INF and that gets stripped during the compile. Long ago Charlie checked in a jar that just contained the ruby stdlib and put it in the root path. Since we're using jruby-jars we'll need to do the same thing in a rake task as part of the install.

Warning from Dex

Compiling always includes this:

-dex:
Converting compiled files and external libraries into /Users/daniel/code/scratch/name/bin/classes.dex...
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)

Things still work; I've just been ignoring it. But if it's an easy fix, we might as well do it.

Starting a service from an activity broken on 0.1.0

The conditional setup of RubotoService in the new ruboto.rb breaks starting a service from an activity.

When ruboto.rb is first loaded, only $activity is set. Later, when we try to activate a service, RubotoService is not set up.

I have removed the conditional around setup at the bottom of ruboto.rb for now.

Make stack trace for exception raised in $activity.handle_create reflect correct source file

A stack trace for an exception raised in handle_create now looks like this:

W/System.err( 526): org.jruby.exceptions.RaiseException: (NameError) undefined local variable or method `no' for #Java::NoJujutsuAndroidOppmote::OppmoteActivity:0x47f61718
W/System.err( 526): at org.jruby.RubyKernel.method_missing(org/jruby/RubyKernel.java:238)
W/System.err( 526): at Java::OrgRuboto::RubotoActivity.method_missing(./ruboto.rb:96)
W/System.err( 526): at #Class:0x1485c4a40.(root)(<script>:34)
W/System.err( 526): at org.jruby.RubyKernel.instance_exec(org/jruby/RubyKernel.java:2024)
W/System.err( 526): at Java::OrgRuboto::RubotoActivity.when_launched(./ruboto.rb:216)
W/System.err( 526): at Java::OrgRuboto::RubotoActivity.handle_create((eval):3)
W/System.err( 526): at #Class:0x147fb7260.(root)(<script>:12)

The exception happened in <script>:34 We should replace <script> with the actual source file name.

cannot generate app

I can't generate the app with ruboto

I try also the path "./fishmonger" but I've the same error.

C:\prjandroid>ruboto gen app --package us.cirion.ruboto.demo --path ./fishmonger --name Fishmonger --target android-8 --activity Fishmonger

Generating Android app Fishmonger in C:/prjandroid/fishmonger...F, [2011-06-17T17:49:25.656000 #6116] FATAL -- : No such file or directory - No such file or directory - ./fishmonger (Errno::ENOENT)
org/jruby/RubyDir.java:317:in chdir' c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/ruboto-core-0.1.0/lib/ruboto/commands/base.rb:70:inrun'
c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/main-4.2.0/lib/main/program/class_methods.rb:147:in run' org/jruby/RubyKernel.java:1191:incatch'
c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/main-4.2.0/lib/main/program/class_methods.
rb:135:in run' c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/main-4.2.0/lib/main/factories.rb:18:inrun'
c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/main-4.2.0/lib/main/factories.rb:25:in Main' c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/ruboto-core-0.1.0/lib/ruboto/commands/base.rb:21:inmain'
c:/jruby-1.6.2/lib/ruby/gems/1.8/gems/ruboto-core-0.1.0/bin/ruboto:5:in `(root)'

org/jruby/RubyKernel.java:1063:in load' c:\jruby-1.6.2\bin\ruboto:19:in(root)'

C:\prjandroid>ver

Microsoft Windows XP [Versione 5.1.2600]

C:\prjandroid>jruby -v
jruby 1.6.2 (ruby-1.8.7-p330) (2011-05-23 e2ea975) (Java HotSpot(TM) Client VM 1.6.0_26) [Windows XP-x86-java]

C:\prjandroid>gem list

*** LOCAL GEMS ***

arrayfields (4.7.4)
bouncy-castle-java (1.5.0146.1)
fattr (2.2.0)
jruby-jars (1.6.2)
jruby-openssl (0.7.4)
jruby-win32ole (0.8.3)
main (4.2.0)
rake (0.8.7)
ruboto-core (0.1.0)
sources (0.0.1)

C:\prjandroid>aapt v
Android Asset Packaging Tool, v0.2

C:\prjandroid>

API Documentation

It's looking like we're going to use a lot of metaprogramming, which doesn't mix too well with RDoc, so we'll have to figure something out.

jberkel suggested that we could parse the Android javadoc for some of it, which is a good idea. Making it work--particularly merging metaprogrammed methods we got off of javadoc with methods that we defined ourselves--might be tricky.

Fast development with "rake update_scripts:reload"

Development is really slow because when you update a script, you have to get the script onto the device, kill the app, start the app, wait for JRuby to initialize, and then if there's an error, see it and start over.

I was thinking it might be possible (at least if you're not using the arguments passed to the creation method) doing something similar to Scott's idea for how to do the reflection not on the phone:

http://groups.google.com/group/ruboto/browse_thread/thread/5a18626eab132599#

I played with it for awhile and couldn't make it happen. Now that I think about it, it may not work well because we'd need to make a lot of method calls to make sure, for example, the setup_content block fires right.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.