Monday, 19 April 2010

Port Qt and/or SDL to Android

I've been looking around to see if there are any ports of Qt or SDL to Android. This is by way of comparison to the Airplay SDK.

There are a couple of open-source projects that have been working towards this... though neither look pratical to my eyes at the moment.

Qt port to Android:
http://code.google.com/p/android-lighthouse/wiki/QADK

SDL port to Android:
http://www.anddev.org/viewtopic.php?p=40838

It is a shame that none of the bigger software development companies haven't done this already - the port of Qt would be especially useful!

Sunday, 18 April 2010

Airplay, Android and in-app advertising

I've been thinking around the subject of Android, and am pretty certain that the only tenable model for app distribution on this platform is with in-app advertising.

Of course, porting of a C++ app to Android is a complete pig, and I guess the option is either maybe via a port of SDL, or via Airplay.

The issue with Airplay is how to display in-app advertising; there is no way that I can see to invoke native code from Airplay!

Thinking around the subject, I was wondering if it were possible to install a native Android service that listens to a particular socket.

My thought is that Airplay could communicate with that service via the socket, to send request to display an ad in a native pop-up Window (the service handles the display of the ad, outside of the context of Airplay).

Anybody care to comment on this idea...? :-D

Pete

Monday, 8 March 2010

Performance-tuning example with gcc

From time to time, I need to rip-apart functions to do some old-school performance tuning. This is really easy to do.

Here is an example file, called perf.c ... in it, I have two versions of a function. One is inefficient, the other is more efficient by virtue of being written slightly differently.


typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;


// Inefficient inner loop

void byteswap (const uint8_t *PpFrom, uint8_t *PpDst, uint32_t PBytes)
{
    long i;
    long lWords = PBytes >> 1;

    for (i=0; i < lWords; i++)
    {
        unsigned lWord = ((const uint16_t*)PpFrom)[i];
        ((uint16_t*)PpDst)[i] = ((lWord & 0x0ff) << 8) | lWord >> 8;
    }
}

// Efficient inner loop

void byteswap_2 (const uint8_t *PpFrom, uint8_t *PpDst, uint32_t PBytes)
{
    uint32_t lWords = PBytes / 2;

    uint16_t* PpDstPtr = (uint16_t *)PpDst;
    uint16_t* PpDstEnd = PpDstPtr + lWords;

    const uint16_t* PpFromPtr = (const uint16_t *)PpFrom;
    for (;PpDstPtr < PpDstEnd;)
    {
        unsigned lWord = (*PpFromPtr++);
        (*PpDstPtr++) = ((lWord & 0x0ff) << 8) | lWord >> 8;
    }
}


From the command-line, run this command (assuming you have gcc!)

gcc -c -g -gstabs perf.c perf.s

This takes your source code (perf.c), and outputs the disassembled output to a file called perf.s ... which you can take a look at with your text editor.

In the file, the code generated for the first function looks like this:


.globl _byteswap
.def _byteswap; .scl 2; .type 32; .endef
_byteswap:
LFB3:
.file 1 "perf.c"
.loc 1 9 0
pushl %ebp
LCFI0:
movl %esp, %ebp
LCFI1:
subl $16, %esp
LCFI2:
.loc 1 11 0
movl 16(%ebp), %eax
shrl %eax
movl %eax, -8(%ebp)
.loc 1 13 0
movl $0, -12(%ebp)
jmp L2
L3:
LBB2:
.loc 1 15 0
movl 8(%ebp), %edx
movl -12(%ebp), %eax
addl %eax, %eax
leal (%edx,%eax), %eax
movzwl (%eax), %eax
movzwl %ax, %eax
movl %eax, -4(%ebp)
.loc 1 16 0
movl 12(%ebp), %edx
movl -12(%ebp), %eax
addl %eax, %eax
leal (%edx,%eax), %ecx
movl -4(%ebp), %eax
movl %eax, %edx
sall $8, %edx
movl -4(%ebp), %eax
shrl $8, %eax
orl %edx, %eax
movw %ax, (%ecx)
LBE2:
.loc 1 13 0
addl $1, -12(%ebp)
L2:
movl -12(%ebp), %eax
cmpl -8(%ebp), %eax
jl L3

.loc 1 18 0
leave
ret



The code generated for the second function looks like this:


.globl _byteswap_2
.def _byteswap_2; .scl 2; .type 32; .endef
_byteswap_2:
LFB4:
.loc 1 21 0
pushl %ebp
LCFI3:
movl %esp, %ebp
LCFI4:
subl $32, %esp
LCFI5:
.loc 1 22 0
movl 16(%ebp), %eax
shrl %eax
movl %eax, -20(%ebp)
.loc 1 24 0
movl 12(%ebp), %eax
movl %eax, -16(%ebp)
.loc 1 25 0
movl -20(%ebp), %eax
addl %eax, %eax
addl -16(%ebp), %eax
movl %eax, -12(%ebp)
.loc 1 27 0
movl 8(%ebp), %eax
movl %eax, -8(%ebp)
jmp L6
L7:
LBB3:
.loc 1 30 0
movl -8(%ebp), %eax
movzwl (%eax), %eax
movzwl %ax, %eax
movl %eax, -4(%ebp)
addl $2, -8(%ebp)
.loc 1 31 0
movl -4(%ebp), %eax
movl %eax, %edx
sall $8, %edx
movl -4(%ebp), %eax
shrl $8, %eax
orl %eax, %edx
movl -16(%ebp), %eax
movw %dx, (%eax)
addl $2, -16(%ebp)
L6:
LBE3:
.loc 1 28 0
movl -16(%ebp), %eax
cmpl -12(%ebp), %eax
jb L7

.loc 1 33 0
leave
ret


I've highlighted the assembly of the code generated for the two inner loops. Look how much more efficient the second version is, with only a simple bit of re-coding!

It should be easy using this approach to learn how to make your code more efficient, without much effort.

Monday, 1 March 2010

VisualBox, VMWare Player and Parallels

I've done quite a bit of work over the past year with PC-hosted Linux (Ubuntu) VMs under VMWare Player, mainly for Android work. I got so fed up recently with the poor system integration (poor Mouse and Keyboard transitioning when moving to/from host and the VM, no copy/paste between Windows and the VM, limited support for VM desktop resizing, not easy to share file data between host and VM), that I decided to spend some time looking at VirtualBox.

After a day evaluating, I've now moved entirely to VirtualBox! I was even able to (easily) set-up 64-bit VMs running on 32-bit Windows, which was very handy; and it was simple to set-up a shared file area between host and VM.

I haven't yet tried VirtualBox on Mac, but I'm perfectly happy with Parallels 5 at the moment so haven't felt the need to use anything else on Mac...

Tuesday, 16 February 2010

Windows 7 on my Mac

I finally took the plunge a few weeks back, and upgraded my Mac Book Pro hard drive (requiring a week with the Apple repair center to do the upgrade!), in preparation for replacing the Windows XP Boot Camp partition with a Windows 7 installation (with Windows XP moved from Boot Camp to a Parallels VM).

The transition was fiddly; I used Parallels Transporter to copy the Boot Camp XP to a virtual machine image on an external USB drive (which I then copied to the Mac Hard Drive). I had to use a USB drive, as I couldn't get Parallels Transporter to work over my LAN. Once I'd proved that the VM started OK (and was backed up to my RAID drive!), I then got rid of the boot camp partition, and tried to install Windows 7 in a larger Boot Camp partition. However... I found was that the Mac drive was too fragmented to resize the Boot Camp partition (!).

I did some reading around the subject, and was surprised to find that Macs don't have a defragmenter option...! My solution was not much fun, but was easier than it sounds: I cloned-off the hard drive using the incredible Super Duper! to another spare USB drive, double-checked that I could boot off that drive; then cloned-back the Super-Dupered drive back to replace the contents of my Mac Book drive. That fixed the fragmentation, so I could finally configure the Boot Camp partition as I wanted and proceed with installing Windows 7.

I chose a 64-bit install of Windows 7 so that I could use Mixtikl and Noatikl VST plug-ins in 64-bit mode under Windows.

Using 64-bit so far hasn't caused me too many problems; Beyond Compare (which is still isn't available in a 64-bit version) did't integrate at first with Windows Explorer. However, thanks to a comment from Aaron from Scooter Soft (see below), I found the configuration option that let me re-configuration as a shell extension, which now works perfectly!

There is also a 64-bit version of Tortise SVN which integrates with Windows Explorer OK. There is also a new version of Cygwin that works fine with Windows 7, and I found a 64-bit copy of GVim that integrates with Windows Explorer.

All in all, Windows 7 is quite a bit faster than XP (though still not as fast as Mac OS!), and is in general easier to use now that I've customised Windows Explorer to work more like that in Windows XP. After a week of use, XP already seems dated and I have no intention of going back to it other than for occasional software testing! I also love the way that out-of-the-box, Windows 7 gave me a read-only view of the HFS partition on my Mac.

So, what about a Windows 7 virtual desktop manager (Mac has the wonderful spaces built-in)? Well, simply install VirtuaWin - it works beautifully, and is open source!

Finally, you'll need Cygwin to get a greate scripting environment, which lets you share scripts between Windows and Mac.

That said, there are far more tools for Windows than for Mac... so I am happy to use both Windows and Mac, mixing-and-matching where required. Where would I be without Beyond Compare and Tortoise SVN on the Windows side, for example? :) The combined Mac OS X/Windows/Parallels/Bootcamp system really is a good one for code development...

64-bit Noatikl and Mixtikl...

I'm currently working on creating 64-bit versions of Noatikl and Mixtikl...

This is made easier for us on the Mac, which supports the use of Universal Binaries; there is quite a lot more fiddling around to do on Windows, where I have to build both separate binaries and a dual-configuration install that includes both 32-bit and 64-bit components.

Incidentally, using Inno Setup makes building a mixed-mode install very easy; what a great tool.

Of course, having both 32-bit and 64-bit binaries makes testing even more time-consuming than usual...!

Tuesday, 9 February 2010

cygwin - alternative shells

While I love cygwin, I've never been totally happy with the standard Cygwin Shell Console, mainly in the way that it handles copy/paste, fonts and colour setting. But mainly copy/paste. :)

Well, I've finally got around to reseaching some replacements, and like what I've found!

Basically, I found a couple of good alternatives: mintty and rxvt. Neither of these require use of X, and both are available as optional packages that you can select from the standard cygwin installation.

Note: neither of these work right with non-cygwin utilities that require piping. You need to keep the normal Cygwin Shell Console for that.

mintty (http://code.google.com/p/mintty/)

When you install this as a cygwin component, you'll find a shortcut created for you automatically under the Start menu.

Next, I modified the shortcut to look like this:

C:\cygwin\bin\mintty.exe bash -li

However, when I started cygwin using this shortcut, my normal .profile scripts weren't picked-up properly. To fix this, I had to modify /etc/profile and add a line like this...

export HOME=/cygdrive/c/home

mintty then launches.

What I love about this is that it gives a fully UTF-8 enabled shell, where it is really easy to cut/copy/paste text, and very easy to change colour schemes.

Just right-click on a mintty window to see the copy/paste etc. options; dead easy.

If you want to spawn-off a new console, use an alias like this:

alias mintty='mintty --size=100,70 bash --login -i &'

mintty

rxvt

This is also available under cygwin, but isn't fully Unicode aware, so isn't as good as mintty. You'll see problems for example when you try viewing a manual page; look at the funny text you get when you try this...:

man bash

That said, here is what I did to get it working.

Basically, I took a copy of the cygwin.bat file, and modified part of it like this:

rem bash --login -i
rxvt -sr -sl 2500 -sb -geometry 100x70 -fg black -bg white -tn rxvt -fn "Lucida Console-12" -e /usr/bin/bash --login -i

I also created an alias in my .profile file, that allows me to launch new rxvt windows easily.

alias rxvt='rxvt -sr -sl 2500 -sb -geometry 100x70 -fg black -bg white -tn rxvt -fn "Lucida Console-12" -e /usr/bin/bash --login -i&'

With rxvt, you get a paste operation in one of two ways:
- Ctrl-Shift-LeftButton
- middle (press mouse wheel) - no good for MacBook devices with Track pad!

Monday, 25 January 2010

Sunday, 24 January 2010

vim - how to force .cpp files to have Objective-C syntax highlighting

This one has bugged me for a while - how to make vim and MacVim display .cpp files with full Objective-C++ syntax highlighting.

This is actually really easy to do; I can't believe it took me so long to figure out! Especially as I try to avoid using .m or .mm files in my projects, and almost exclusively use .cpp source files in all that I do to make my cross-platform work easier...

Anyways: all you have to do, is put these three lines in ~/.vim/filetype.vim (you'll almost certainly first have to create the .vim folder under your home directory...)


au BufNewFile,BufRead *.cpp set filetype=objcpp
au BufNewFile,BufRead *.h set filetype=objcpp
au BufNewFile,BufRead *.c set filetype=objcpp


Sorted! Whenever you use the built-in vim, or MacVim, to edit a .cpp/.c/.h file, you'll see any Objective-C code in your editor displayed with nice syntax highlighting; your C++ code will also look lovely too!

Monday, 18 January 2010

Mixtikl update for iPhone coming soon - and Liptikl!

Tim and I both had a good break over Christmas; I think we both earned it after the long, hard push to releasing Mixtikl 2!

Now that we're refreshed, we've been busy working on an update to Mixtikl, which tidies-up various loose ends and generally makes it easier to get into! We're aiming to release this in a few weeks.

We've also been working on an iPhone version of Liptikl, which is fun and easy to use, so we hope to release that at some point after first releasing the Mixtikl update.

For those who are interested in the technicalities of such things things, most of the primary development for Mixtikl is done under Xcode on the Mac, targeting the iPhone version. Because Mixtikl is 95% cross-platform, I actually have the option to work under either Windows (with Visual Studio) or Mac OS (with Xcode). Despite Visual Studio being hugely more powerful than Xcode (with a far nicer editor model, debugger etc. etc....), I find myself working mainly in Xcode. Why? Simply because Mac OS is a great deal faster than Windows for running all my development scripts. Xcode is a lot less nice to use than Visual Studio, but overall I'm faster on the Mac because Mac OS mainly because shell scripting runs so much quicker...! Because I use the same editor on both platforms (vim ...) I can move easily between the two whenever I need to. I must say however, that if cygwin scripting were a lot faster under Windows, then I'd be back to Windows. :)

Android - NPAPI plugin - how to make a callback from the main thread

If you happen to be writing a browser plug-in using NPAPI/JNI for Android's built-in browser, and are doing some processing in the native side in C/C++ in a separate Posix thread; and want to get a callback into your native code from the main browser thread; you want to use this NPAPI function...!

void NPN_PluginThreadAsyncCall(NPP instance,
void (*func)(void *),
void *userData);

You can find some documentation on this if you search your Android source code for the file called npapi.cpp.

Basically, you call the above function from your native thread to register a callback function; the call to NPN_PluginThreadAsyncCall returns immediately. At some future point in the very near future, the browser will call your supplied function from the main browser thread, supplying the userData that you provided when you registered your callback.

Incidentally, if your Plug-in method is passed a JavaScript object that you're going to need to do something with at a later point (e.g. if you want to issue a deferred callback, through use of NPN_PluginThreadAsyncCall), you need to remember to keep your JavaScript object alive until you're ready to use it, by calling:

NPObject *NPN_RetainObject(NPObject *npobj);

Once you've used the object, remember to release it with:

void NPN_ReleaseObject(NPObject *npobj);

Hopefully that'll be of use to some people!

Friday, 15 January 2010

Android - how to obfuscate your apps

If you're wondering how to obfuscate your Android apps, you should look at http://proguard.sourceforge.net/ ...!

Monday, 4 January 2010

Android debugging with gdb?

For those of you that have been struggling to find information on how to debug under Android with GDB (for example, if you've been writing JNI code for Android...), this looks like a useful link to follow!

http://pdk.android.com/online-pdk/guide/debugging_gdb.html

Pete

Tuesday, 8 December 2009

My first Mix Tikl!

http://t1kl.me?2PJAAIAAAAAAAAdpAqAAABOSBwAAACgkCYAAAC5IDgAAAMaQaAAAAVEAAAAACoAAAAAAVAAAAAACoAAAAAAVAAAAAACpAAAAAAVIAAAAAAA==

Amazing stuff. :-)

Mixtikl 2 launch day - at last!

So here we are, Mixtikl 2 launch day.

Product launch days are always a bit hard, there is always too much to do, and we're focused for now purely on completing the web side of things.

The good news of course is that the software is stable and we're pretty happy with what we've created.

As always, we're wondering what people will think of how we've changed and extended things. Of course, Mixtikl 2 looks quite a lot different to Mixtikl 1, some aspects of the UI have changed a lot and will take some getting used to for users of Mixtikl 1.

We've featured generative content very strongly, and added what we think are some exciting new features aimed at collaboration and content sharing through text audio vectors. And, of course, we're now running on iPod/iPhone; I should think that some people will be interested to compare and contrast the experience of using Mixtikl on iPhone/iPod, compared to Windows Mobile. :)

The biggest challenges for Mixtikl have been of our own making: a continued wish to have it run on as many platforms as possible; to have Mixtikl be usable on both touchable and non-touchable devices; to introduce extensive content sharing features which build on our long experience of "vector audio"; to introduce web browser plug-in variants.

Whatever we do, we know that some people will love Mixtikl 2, others will hate it - and the struggle to create compelling generative software continues!

Life certainly would be easier if we just supported one platform and just focused on one major feature; but then Mixtikl simply wouldn't be so interesting and kaleidoscopic! :)

Pete

Friday, 20 November 2009

Moving to Android NDK 1.6 from Android NDK 1.5 ...

I've updated my Android configuration to NDK 1.6, and am using the latest STLPort download.

There were a few things that changed, mainly system paths, as some posters to my blog were kind enough to point-out in earlier posts.

Here are some notes on that process, from the point of view of a cygwin-based setup under Windows. The comments generally apply to Linux/Mac as well, however.

Getting STLPort

I performed the "git" command for STLPort from within the root of the Android NDK folder, in other words from within this folder:

C:\android-ndk-1.6_r1

The command to use is this:

git clone git://umbel.mooo.com/ndk-wrappers.git

This puts the STLPort code in a slightly different place to where it was before, such that the code appears under the ndk-wrappers folder...


ndk-wrappers\stlport


... which you'll need to account for when you update the paths!

There were a couple of other things that I found tricky to get right in this transition were as follows.

env.sh

When you try running env.sh, you must do it with "source" otherwise the environment isn't updated properly. In other words, type this:

source ./env.sh


Application.mk

If your project is called "fred", then you need to have the following folder:

C:\android-ndk-1.6_r1\apps\fred

This should contain just one item, which is the Application.mk file, with the following (example!) two lines in it:

APP_PROJECT_PATH := /cygdrive/c/DOCUME~1/me/MYDOCU~1/WORKSP~1/fred
APP_MODULES := fred

libstlport.a

Once you've rebuilt STLPort, you need to copy libstlport.a (which seemed to be called libstlport.5.1.a in the previous build system... again, watch out for that!) to a new folder, which you'll need to create in the following location:

C:\android-ndk-1.6_r1\out\apps\fred\libs

The jni folder

You need to have at least two files (your source .cc file, and your Android.mk file) in the jni folder under your project, which is here in my example:

C:\Documents and Settings\me\My Documents\workspace\fred\jni

Android.mk

In my example, the Android.mk file contains this data:


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

STLPORT_BASE := /cygdrive/c/android-ndk-1.6_r1/ndk-wrappers/stlport


LOCAL_MODULE := fred
LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS += -I$(STLPORT_BASE)/stlport \
-D__NEW__ \
-D__SGI_STL_INTERNAL_PAIR_H \
-DANDROID \
-DOS_ANDROID
LOCAL_SRC_FILES := fred.cc

#Static Libraries:
LOCAL_PREBUILT_LIBS := libs/libstlport.a
include $(BUILD_MULTI_PREBUILT)
LOCAL_STATIC_LIBRARIES := libs/libstlport

include $(BUILD_SHARED_LIBRARY)


Good luck!

That should be enough to get you up-and-running with NDK 1.6!

Wednesday, 4 November 2009

Mixtikl 2 - coming December 8th 2009

The Mixtikl 2 release date has now been set at December 8th 2009.

Can't wait! :)

Thursday, 8 October 2009

Mixtikl update

After a long push, Mixtikl 2 is now feature complete! We're now focussed on tidying-up a few loose ends, meaning that there is a good chance we'll be able to release for Mac/Win/Windows Mobile at the end of the month. We'll also submit the iPhone/iPod version to the app store at that time; that'll arrive at such time as Apple approve it!

Amongst all the other stuff we've done for Mixtikl 2, we've created Mixtikl internet browser plug-ins for Mac and Windows, meaning that you'll be able to publish your Mixes and Partikl tracks on-line. Which is pretty cool! :)

Thursday, 10 September 2009

How create a new JNI / STL based project for Android

Now that I've been through the process of creating new JNI / STL-based projects for Android a few times, I thought I'd summarise the steps; as you can see, they are pretty complicated! The problem isn't down to STL; the problem is one of the basic complexity of setting up a JNI-based project (which is never easy to get started, but is fine once you're up and running!).

Note: the steps below assume you're using cygwin and Windows. You'd need to tweak them a little if you're using Mac or Linux.

1. Make sure Eclipse uses a sensible workspace folder

NOTE!! I modified my Eclipse preferences to put my files in
Documents and Settings/myname/My Documents/workspace
rather than the Eclipse default of
Documents and Settings/myname/workspace
which I find really difficult to track-down and/or backup!

2. Create a new Android Java project.

a) Create a package called com.mycompany.MyStl, with your activity class called AdaptorClass

Ensure the following code is in your ActivityClass source code...


// A native method that is implemented by the
// 'libMyStl' native library, which is packaged
public native String stringFromSTL();

// Note: remember to put-in some test code that calls the above native method!!

// this will load the 'libMyStl.so' library on application startup.
static {
System.loadLibrary("MyStl");
}


b) you must add a "libs" folder to your project: and then add an "armeabi" sub-folder in this folder.

c) Build the project (and fix any compilation errors) - but don't run it yet!

3. Create the JNI / STL project

a) Create a folder in for your project, e.g.:


C:\android-ndk-1.5_r1\apps\MyStl


b) Create a file in this folder called Application.mk, which contains the following:


APP_PROJECT_PATH := /cygdrive/c/DOCUME~1/MYNAME/MYDOCU~1/WORKSP~1/MyStl
APP_MODULES := MyStl


NOTE!! The path is a path with no spaces (as otherwise the Android NDK make system gets confused...!), and was generated using cygwin's cygpath command. You must generate and use one that suits your user, using a command similar to the following...


cygpath -dm /cygdrive/c/Documents\ and\ Settings/myname/My\ Documents/workspace


c) Make an empty folder in this folder called "project".

4. Create the JNI / STL sources, and integrate with your Android project:

a) Create a folder for your C++ source code, e.g.:


C:\android-ndk-1.5_r1\sources\MyStl


b) Create a file in this folder called Android.mk ...


LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

STLPORT_BASE := /cygdrive/c/android-ndk-1.5_r1/stlport

LOCAL_MODULE := MyStl
LOCAL_CPP_EXTENSION := .cc
LOCAL_CFLAGS += -I$(STLPORT_BASE)/stlport \
-D__NEW__ \
-D__SGI_STL_INTERNAL_PAIR_H \
-DANDROID \
-DOS_ANDROID
LOCAL_SRC_FILES := MyStl.cc

LOCAL_STATIC_LIBRARIES := /../../../../../stlport/build/lib/obj/gcc/ar/libstlport.5.1

include $(BUILD_SHARED_LIBRARY)


c) Create a file in this folder called MyStl.cc ... note the instructions that follow in d) on how to re-generate your own method prototypes...!


/*
* Class: com_mycompany_MySTL_AdaptorClass
* Method: stringFromSTL
* Signature: ()Ljava/lang/String;
*/

// Prototype - make sure it uses C-style linkage!
extern "C"
{
JNIEXPORT jstring JNICALL Java_com_mycompany_MyStl_AdaptorClass_stringFromSTL
(JNIEnv *, jobject);
};

// Implementation
JNIEXPORT jstring JNICALL Java_com_mycompany_MyStl_AdaptorClass_stringFromSTL
(JNIEnv *env, jobject)
{
std::vector lVector;
lVector.push_back("Hello from STL!");

std::string simple_string = lVector[0];

return env->NewStringUTF(simple_string.c_str());
}


d) Modify the MyStl.cc file...

The prototype and implementation shown are just examples. You MUST construct your own by doing this:


cd "/cygdrive/c/Documents and Settings/myname/My Documents/workspace/MySTL/bin"
javah -jni com.mycompany.MySTL.AdaptorClass_MySTL


Copy-out the generated prototype from the generated .h file that javah creates for your, and replace what I've shown above with the correct generated function prototype and function name.

e) Then, build the library:


cd $NDK_HOME
./env.sh
make APP=MySTL


f) The first time you've built the library, you must drag the newly constructed .so file from Windows Explorer to your armeabi folder in the project. You must then right-click on the armeabi folder in Eclipse, and select "Refresh". The library is then bundled-in to your project bundle when you next build your Android project.

5. You can now build and run your Android project!

6. If you ever modify your C++ source...

Simply re-build the library (step 4e) and then re-build and run your Android project (step 5).

7. If you need to add a new method...

You'll need to re-use javah to generate the correct prototype function signature to use. Add this to your STL project, re-make, re-build and you're done!

Tuesday, 8 September 2009

Android Lists - using the ListView component

Whenever I write GUI code for a platform that is new to me, I always find myself stumped early-on figuring-out how to get simple list gadgets working. After all, most simple applications are based around buttons and lists of data. Buttons are always easy to use, but lists are always a pain.

Every platform seems to use a completely unique approach to creating lists; Android's approach is no exception in terms of how difficult it is to figure-out how to use its LiewView components. My opinion here is that the problem is down to the trend for using Model-View-Controller architectures, which actually seem to get in the way of deploying basic components like a list.

Anyways: you'll find a really useful guide to creating multi-column lists on Android here.

The steps you need to follow:
- create a new res/layout/mylayout.xml file, with the correct magic format and properties that you have to copy from what you can glean through internet searches
- use some magic code based around Adapter classes
- call the setAdapter method on your list

For those who are interested, I think the Windows API model is by *far* the easiest (using owner-draw lists); a piece of cake to use. The Apple APIs (carbon/cocoa) are hideous. The Android APIs are probably the worst.

I really wish that people who wrote APIs would concentrate on making the basic stuff easy, with lots of example code. Well done Microsoft for getting this stuff right in the first place. :)

The good news about Java development these days is support for Java Generics; I'm very happy to find that Android supports them!