From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4cb1f8d1c17d39a8,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.73.233 with SMTP id o9mr15130007pbv.8.1319678337682; Wed, 26 Oct 2011 18:18:57 -0700 (PDT) Path: p6ni1431pbn.0!nntp.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Ada 'hello world' for Android; success! Date: Wed, 26 Oct 2011 21:18:47 -0400 Message-ID: <8239efcjuw.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (windows-nt) Cancel-Lock: sha1:Hi1yMJN6cxhRmTRfL13V419tBQg= MIME-Version: 1.0 X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 718154ea8b181e029e66115014 Xref: news1.google.com comp.lang.ada:18711 Content-Type: text/plain; charset=us-ascii Date: 2011-10-26T21:18:47-04:00 List-Id: 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 -- $ 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 ;). -- -- Stephe