Re: Ada 'hello world' for Android; success!
- From: Jeffrey Creem <jeff@xxxxxxxxxxxxx>
- Date: Thu, 27 Oct 2011 06:50:55 -0400
On 10/26/2011 9:18 PM, Stephen Leake wrote:
I've managed to get an Ada 'hello world' working on Android. It follows
the example at
http://developer.android.com/resources/tutorials/hello-world.html
translated to Ada.
Here's the Ada 'main program':
with Android.App.Activity;
with Android.OS.Bundle;
package Hello is
--<Ada package>$<Ada type> must match ../AndroidManifest.xml manifest | application | activity | android:name
type Typ is new Android.App.Activity.Typ with null record;
overriding procedure OnCreate
(This : access Typ;
savedInstanceState : access Standard.Android.Os.Bundle.Typ'Class);
pragma Export (Java, OnCreate, "onCreate");
end Hello;
-- Prefix must match ../AndroidManifest.xml manifest | package
pragma Export (Java, Hello, "net.example.helloada.hello");
package body Hello is
overriding procedure OnCreate
(This : access Typ;
savedInstanceState : access Standard.Android.Os.Bundle.Typ'class)
is
type Super_Ref is access all Android.App.Activity.Typ;
begin
Android.App.Activity.Oncreate (Super_Ref (This), savedInstanceState);
-- FIXME: use R.layout
--
-- need to run jvm2ada on ../gen/net/example/R.java, but that's
-- generated by the ant process that runs after this code is
-- compiled, so we have to learn how to break that up or
-- something.
--
-- until then, get this constant from R.java (value for 'layout')
Android.App.Activity.SetContentView (Android.App.Activity.Ref (This), 16#7f030000#);
end OnCreate;
end Hello;
It runs on the Android emulator provided with the Android SDK, and on my
HTC Inspire.
As you can see, there are still some rough edges in the build process. I
could have hard-coded the 'hello' string here, but that's not what the
Java program does; this demonstrates that the Ada code really is using
all the Java GUI resources and classes properly.
Mostly I didn't want to spend any more time figuring out how to
customize the Android SDK build tools. They work really nicely if you
are doing simple Java stuff, but really get in the way when you want to
do something more complicated.
I started with GNAT GPL 2011, jvm target. I had to fix two bugs in
jvm2ada, one bug in the jvm-gnat backend (all reported to AdaCore with
patches), and work around another bug in the gnat front end (also
reported to AdaCore). Not too bad :).
Any suggestions for where to post more info?
wikibooks.org/wiki/Ada_Programming looks like a good place, but I'm not
sure where this fits in that hierarchy.
I can post a .tar.gz (or just the .apk :) on my own website if anyone is
interested in getting a quick look now.
There are some interesting issues in the Ada<-> Java mapping; for
example, Ada packages map to Java nested classes, so you have to put the
desired Java package name in the 'pragma Export' external name.
Figuring out how to tell the SDK build tools exactly what was going on
was the most frustrating; the documentation on those is totally
inadequate. I managed to find some answers in the source code for the
tools; at least it is all open source.
Fixing the bugs in the GNAT tools was easy by comparison, once I had
test cases.
Now I can work on my music player app, and get away from Java ;).
Perhaps a new sourceforge project, or get it posted into the existing GNU Ada project?
.
- Follow-Ups:
- Re: Ada 'hello world' for Android; success!
- From: Stephen Leake
- Re: Ada 'hello world' for Android; success!
- References:
- Ada 'hello world' for Android; success!
- From: Stephen Leake
- Ada 'hello world' for Android; success!
- Prev by Date: Re: Length of unbounded_string.
- Next by Date: Re: Ada 'hello world' for Android; success!
- Previous by thread: Re: Ada 'hello world' for Android; success!
- Next by thread: Re: Ada 'hello world' for Android; success!
- Index(es):
Relevant Pages
|