RFO Basic! for Android™ – Programming for Android on Centos/RHEL

By Frank Cox

(Jan 1, 2014)

RFO Basic! for Android is the most straightforward method for writing an Android App that I am currently aware of. RFO Basic! for Android is also Free Software licensed under the terms of the GPL. A very helpful web forum for RFO Basic! programming discussions is here.

This article is a collection of random notes intended to make life as easy as possible when writing an Android app on a Linux platform, specifically Centos or RHEL though these notes will have application to other Linux distributions as well.

To create a stand-alone Android app using Basic! for Android you must install Eclipse and the Android SDK so you can compile Basic! itself. A stand-alone app written in Basic! is merely a copy of Basic! itself that has been compiled into an apk that includes the resources that you require to run your program. You must name your Basic! program my_program when you compile it; this has an effect similar to autoexec.bat under DOS; i.e. Basic! will automatically execute my_program on startup, thereby turning your apk into a stand-alone app that runs only the program that you compiled into the apk.

The Android Developer Tools Bundle also provides an Android Virtual Device so you can run Android apps on your computer desktop.

1. Installing the Android SDK and Eclipse Development environment

Installing the Android SDK and Eclipse is a relatively painless process on Centos 6. You require the following packages that may not already be present on your system:

yum install java-1.7.0-openjdk-devel.x86_64 glibc.i686 glibc-devel.i686 libstdc++.i686 zlib-devel.i686 ncurses-devel.i686 libX11-devel.i686 libXrender.i686 libXrandr.i686

Note the i686 packages that are required since Android is currently a 32-bit operating system. If you are using the 32-bit distribution of Centos, you probably have those packages by default. Also, if you are using a 32-bit version of Centos, you require java-1.7.0-openjdk-devel.i686 instead of the x86_64 version listed above. The above package list gets you set up to run an Android development environment on the 64-bit version of Centos.

Now you need the ADT Bundle, which comes with everything you need to develop Android apps, including Eclipse. I recommend using the ADT Bundle and the version of Eclipse that comes with it; I tried installing the Android SDK tools alone with the objective of using the Centos-native Eclipse from the Centos base repo but rapidly determined that it would be more trouble than it's worth. Centos-native Eclipse drags in a ton of dependencies, and it's an older version than the one that is recommended by Google for Android development. Therefore, the least painful solution is to download the Android ADT bundle for Linux from here and install that. After downloading the ADT bundle, pick a directory on your system and unzip the archive into that. That's it. The install is now completed. You now have two subdirectories, eclipse and sdk. Run the eclipse binary in the eclipse directory and the SDK is ready to go.

2. Creating an Android Virtual Device

You can have as many Android Virtual Devices as you want, but you will need at least one to install Basic! into so you can run the programs that you develop.

Click on the Android Virtual Device Manager icon:

Create a new Android Virtual Device by clicking on New. Be sure to specify that you want a SDCARD installed.

After you have it in place, click on Start to boot it up. You'll probably want to click on the “Scale Display to Real Size” option when you start it or it will be huge. (The un-scaled display is useful when creating screenshots of your app for posting on Google Play.

After it finishes booting, you have a fully-functional Android device running on your desktop.

3. Installing RFO-BASIC on the Android Virtual Device

Download the latest version of Basic! from here. You want the APK to install on your Android Virtual Device, and you will want the source code when you wish to compile a stand-alone Android app.

The Android Debug Bridge is a command-line tool that lets you communicate with your emulated Android Virtual Device. (You can also communicate with a real Android device using adb if you want to.)

You can find adb in the sdk/platform-tools subdirectory that was created in Step 1 of this article. For convenience, you may wish to create a symbolic link to adb in your ~/bin directory.

This is the command to install Basic! on your Android Virtual Device:

adb install /path/to/Basic.apk

Note that the Android Virtual Device must be booted up and unlocked for this to work.

4. Using the Geany Programming Editor with Basic!

While you can use any text editor to write Basic! programs, my favourite programming editor is Geany. (Click here to download geany for Centos 6.) It is not difficult to set up Geany to automatically push Basic! programs to your device and run them. I run geany full-screen and click the “Always on top” menu option on the AVD so the device is always visible on the bottom corner of my monitor while editing Basic! Programs. Create a geany project for Basic! and you can set the build options to handle communications with your AVD.

Select BuildSet Build Commands.

The Compile command is:

adb push %d/%f /sdcard/rfo-basic/source/

The Execute command is:

adb shell am force-stop com.rfo.basic && adb shell am start -n com.rfo.basic/com.rfo.basic.Basic -d /sdcard/rfo-basic/source/%f

The Compile command will copy (or push) your .bas file to the AVD. The Execute command will kill any currently running instances of Basic!, then reload it and run the .bas file.

Accordingly, the steps to run a Basic! program directly from Geany on an Android Virtual Device are as follows:

Save to save the file.
Compile to push the file to the AVD.
Execute to kill any previous instances of Basic! and run your program on the AVD.

5. Running the AVD Manager without Eclipse

You don't necessarily have to run Eclipse if all you need at the moment is to create or boot up an AVD. The command path/to/sdk/tools/android avd will load the AVD Manager stand-alone and you can manage your AVD's from that. (/path/to is the name of the directory where you installed the ADT Bundle.)

6. Writing the Basic! Program and Compiling the App

Writing a Basic! program is beyond the scope of this article. However, there is an excellent user manual for Basic! that can be downloaded here. Appendix D describes the procedure for creating a stand-alone app. Note, however, that if you are using the html.load.url command to show locally stored files in Basic! (such as user interfaces) you must either put the html files into the Android assets folder and not in res/raw, or have your program provide a fully qualified absolute path to the html file, as follows:

FILE.ROOT pathtofiles$
html.load.url "file://" + pathtofiles$ + "/file.html"

Also note that the name of your program must be my_program and not f99_my_program; the current version of the manual is incorrect on that point.

Android is a trademark of Google Inc. Google Play is a trademark of Google Inc.

Other articles written by Frank Cox can be found here.

Frank Cox owns and operates the Melville Theatre in Melville, Saskatchewan, Canada, and has been playing with computers for over 30 years.

Janurary 1, 2014

This work is licensed under a Creative Commons Attribution-Share Alike 2.5 Canada License.