Search

Recent Posts

Tags


« | Main | »

Android G2 programming 101

By Dale Reagan | August 19, 2009

CAVEAT – I’m not a Java programmer so all of the basic information is missing from my arsenal (i.e. naming conventions, common goodies, stuff you should know before you say, “Yea, I’m a Java programmer.”)  With that in mind some of the problems I encountered reflect this lack of knowledge as well as not having any experience with Eclipse (a very nice application.)    Sooo, if the directions leave out any important bit of information then there’s a good chance that I’m going to make newbie type mistakes.

Ok, how easy/difficult will Hello World (or in my case, “Hi Ya’ll!”) be?  On my Fedora 11 (Linux system) I:

I had to work through some OS/Eclipse/Android SDK issues on my system – perhaps your install will be effortless… 🙂    Once all is installed and working then the exploration can proceed.

In Eclipse:

  1. create new Android Project with the same options shown on the tutorial page
  2. modify as indicated in the Hello World example
  3. Run (select ‘Ok’ or affirm any questions from Eclipse
  4. up pops the Android Emulator
  5. after some time the program runs on the Emulator
  6. total time?  just a few minutes.  (It took longer for the emulator to fire up than it took to create the project and send it to the emulator…)

How about changes to the program?

  1. Jump to step #2 above
  2. Edit message from default, “Hello, World” to “Hey Ya’ll”
  3. save changes
  4. run

My expectation is that the new ‘program’ will magically replace the first one.  The result – sort of.  On the emulator I manually delete the application and try again.  At this point I note that my system activity level monitor indicates that the emulator is using significant system resources – just an FYI – don’t leave it running if you are not using it… 🙂

During this process the first newbie item I encountered was Java element naming conventions.  If you don’t use the correct conventions then your ADT generated application will be broken from the start.  I mention this just in case, like me, you are tinkering with the ADT tool (it does a number of checks and things may seem to be Ok but your Java code will be broken if you step outside of Java-approved naming conventions.)

Working with strings.xml

Next I try the alternative approach (i.e. keeping presentation separate from coding.)  I edit the strings.xml file as suggested. The next item in the tutorial is to edit the Class file?  where the heck is that?  Hmm, ok I just move on to Run – the emulator pops up and my new message is displayed.  Ok.

If are you going to program Android in Java then you should review the Android Style Guide before you get started.

Hello Views and other tutorials/docs

There are a number of tutorials that are fairly direct and easy to follow.  You can print documentation but there is no single PDF or other single document that I could locate – you have to print one section at a time.  There are many examples but if you are new to Java they are not the best sources to use for learning a new programming language…

ASE – scripting with Android

I stumbled upon ASE (Android Scripting Environment.) From the ASE web page:  [ASE] brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface...”

Hmm, scripting on a teeny-tiny screen with no real keyboard???  Hmmm.

Scripting with a non-Java language?   Python, LUA and Beanshell are currently supported – this is a bit more interesting.  The tidbit below is from the Android ASE Wiki:

Running Scripts Externally

Sometimes it’s nice to be able to write scripts on your computer and run them on the phone. This is possible using adb’s port forwarding.

First, start an ASE interactive terminal in either Python or Lua. Take note of the AP_PORT variable at the top of the terminal. Next, set up adb port forwarding and set the AP_PORT environment variable locally.

$ adb forward tcp:4321 tcp:<AP_PORT>
$ export AP_PORT=4321

Now you can execute Python or Lua on your PC, import the android package or module for the language, and interact with the AndroidProxy on the phone.

For example, to use your local Python interpreter, make sure you have the ASE android.py module in your Python path (i.e. in site-packages or the current directory).

$ python
Python 2.6
Type "help", "copyright", "credits" or "license" for more information.
>>> import android  # The ASE android.py module should be on your sys.path.
>>> droid = android.Android()
>>> droid.makeToast("Hello from my computer!")

—–

The Bad News for ASE

You need a keyboard (if you want to edit scripts on the device) since the keyboard screen is not currently supported – so a G1 is your only option at this time if you want to edit scripts using ASE. You can still download and run scripts so you could write them on your PC (make much more sense) and then install.

On the G2 the Python 2.6 install failed twice but worked on the third try.  LUA installed with no problems, however ASE crashed several times as I attempted to run the sample LUA scripts… You need to install TTS library (text to speech) to run several of the sample Python scripts.  The TTS install took a looooonnnnnggggg time???  After it was installed the ASE Python scripts did not ‘see’ if so I powered down/up the phone.  I suggest only installing when you have a WiFi connection.  After the download you have to fetch additional files (explained on the TTS web page above.)

What about the Android OS?

You can download (fetch ~4GB of code) for this device.  At this time (8/2009) Java 1.6 is NOT supported (so you will need to revert to 1.5 if running something like Fedora 11…)  If all goes well you can compile the entire system with one command.  If so inclined you can then install your custom build on your Android device (provided you have an unlocked phone) or for use with the Android Emulator.  This is the open part of an Open Source project – want to change things? just download the source, modify, compile and install (sounds simple and perhaps is if you are accustomed to these sorts of activities…)

The really nice thing about this is that you can review ‘the code’ and perhaps figure out why something is not working as expected/desired on the device that you are using with the version of Android that is installed (which is most likely customized by the manufacturer and cell provider.)

Having previously noted the problem with Pop emails not deleting I took a look at the code handling emails.  Seems that things are written with all email management being tied to an external provider, i.e. Google Gmail or similar so the actual management of local files is missing (i.e. you can’t empty the trash – so at this time, don’t delete Pop emails on your G2/MyTouch – delete them from your PC Pop mail client…)

Ok, MyDroid (really)

mydroid]# time make
============================================
PLATFORM_VERSION_CODENAME=Donut
PLATFORM_VERSION=Donut
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=Donut
============================================
************************************************************
You are attempting to build with the incorrect version of java.

Your version is: java version “1.6.0_0”.
The correct version is: 1.5.

Please follow the machine setup instructions at http://source.android.com/download
************************************************************
************************************************************
build/core/copy_headers.mk:15: warning: overriding commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h’
build/core/copy_headers.mk:15: warning: ignoring old commands for target `out/target/product/generic/obj/include/libpv/getactualaacconfig.h’
Install: out/host/linux-x86/framework/apicheck.jar
Install: out/host/linux-x86/framework/clearsilver.jar
Install: out/host/linux-x86/framework/droiddoc.jar
Install: out/host/linux-x86/lib/libneo_util.so
Install: out/host/linux-x86/lib/libneo_cs.so
Install: out/host/linux-x86/lib/libneo_cgi.so
Install: out/host/linux-x86/lib/libclearsilver-jni.so
Copying out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes-full-debug.jar
Install: out/host/linux-x86/framework/dx.jar
Install: out/host/linux-x86/bin/dx
host Executable: aapt (out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt)
/usr/bin/ld: skipping incompatible /usr/lib64/libz.so when searching for -lz
/usr/bin/ld: cannot find -lz

collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/aapt_intermediates/aapt] Error 1

real    0m23.103s
user    0m10.027s
sys     0m7.545s

Soooo – looks like you need to stick with a 586 system to avoid programming/compile issues with a lib64 OS…  BTW – a simple solution would be to build a VM (i.e. using Virtual Box) with a 586 OS install and then compile there…

If you are interested in device programming then this is an excellent gizmo to experiment with – or just use the emulator.  The price of entry into the retail side is only $25 to sell your programs on the Android Market (and of course, since all the development tools are Open Source the cost is significantly less than say, programming for Windows Mobile – which may require the purchase of Microsoft tools and/or other costs.)

At this point I have returned the G2/MyTouch – while it has many interesting features it does not meet my current business needs:  working Pop email and  a direct sync with my PC calendar – I’m simply not interested in putting my data in the cloud and I actually view this as Google forcing their solution on the user; with a Windows Mobile phone I can choose a Microsoft, a Google or some other solution;  if the phone were FREE then I might find Google’s approach more acceptable (we will give you a free phone if you let us track all of your phone activity.)

Topics: Computer Technology, Mobile Web, Unix-Linux-Os, Web Technologies | Comments Off on Android G2 programming 101

Comments are closed.


________________________________________________
YOUR GeoIP Data | Ip: 73.21.121.1
Continent: NA | Country Code: US | Country Name: United States
Region: | State/Region Name: | City:
(US only) Area Code: 0 | Postal code/Zip:
Latitude: 38.000000 | Longitude: -97.000000
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________