13 Nov
Hello Android – Pindah (with Mirah) Application
Did you install the Android SDK / JDK, etc? If not, start here - http://developer.android.com/sdk/index.html.
If you're running 64-bit like me, make sure to install the ia32-libs, since the SDK is 32-bit.
This is completely based on the Hello Android tutorial - I didn't really do a whole lot, but the hope is that this will help get some more ruby devs into android development with a simple how-to.
Step 1 - Setup RVM with jruby
Note: RVM is awesome, if you don't use it or don't know about it - read more here.
rvm install jruby cd /path/to/your/android/pindah/mirah/project/dir/ # using your .rvmrc will trigger `rvm use jruby` when you cd into your project dir. echo "rvm use jruby" > .rvmrc # this will make sure your .rvmrc is working, you should then be able # to use rvm info and see jruby cd .
Step 2 - Install the mirah and pindah gems
# too easy gem install mirah pindah
Step 3 - Create your first pindah app
pindah create com.example.android.hello_world cd hello_world
Step 4 - Create your activity - HelloAndroid.mirah
# from your project dir and inside your pindah app dir <editor> src/com/example/android/hello_world/HelloWorld.mirah
This is the code I used:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.hello_world; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.TextView; | |
class HelloWorld < Activity | |
def onCreate(state:Bundle) | |
super state | |
tv = TextView.new(self) | |
tv.setText("Hello, World!") | |
setContentView(tv) | |
end | |
end |
Step 5 - Setup your AndroidManifest.xml file
This is where you define your app, version, name, etc, but more importantly for this example - what activity will handle your main intent.
Mine looks like this:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.android.hello_world" | |
android:versionCode="1" | |
android:versionName="1.0"> | |
<application android:label="@string/app_name" | |
android:debuggable="true" | |
android:icon="@drawable/ic_launcher"> | |
<activity android:name=".HelloWorld" | |
android:label="@string/app_name"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
Step 6 - Install to your device
# make sure a device is recognized ... # and make sure adb is in your path (platform-tools in the SDK) adb devices rake install