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=0.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4cb1f8d1c17d39a8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.35.68 with SMTP id f4mr45291781pbj.5.1319714103912; Thu, 27 Oct 2011 04:15:03 -0700 (PDT) Path: p6ni3024pbn.0!nntp.google.com!news2.google.com!goblin2!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Jeffrey Creem Newsgroups: comp.lang.ada Subject: Re: Ada 'hello world' for Android; success! Date: Thu, 27 Oct 2011 06:50:55 -0400 Organization: A noiseless patient Spider Message-ID: References: <8239efcjuw.fsf@stephe-leake.org> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="QWtZqFBQtiq0FqDjTxs/XQ"; logging-data="7948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UUs1XoK5MGbDNcyxKT3tMO+sQcViU8y0=" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 In-Reply-To: <8239efcjuw.fsf@stephe-leake.org> Cancel-Lock: sha1:nlyJepHMcoCkQdV2B/SiaIKyv0s= Xref: news2.google.com comp.lang.ada:14205 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2011-10-27T06:50:55-04:00 List-Id: 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 > > --$ 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?