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 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.30.34 with SMTP id p2mr16752711pbh.4.1319699562132; Thu, 27 Oct 2011 00:12:42 -0700 (PDT) Path: p6ni2381pbn.0!nntp.google.com!news2.google.com!news4.google.com!feeder.news-service.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Ada 'hello world' for Android; success! Date: Thu, 27 Oct 2011 09:12:44 +0200 Organization: A noiseless patient Spider Message-ID: References: <8239efcjuw.fsf@stephe-leake.org> Mime-Version: 1.0 Injection-Date: Thu, 27 Oct 2011 07:12:41 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="i/A9DDFtm92PEI+jw3DLWQ"; logging-data="21007"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LCkJmoPTCzqFfnHVBRHxi" User-Agent: KNode/4.7.2 Cancel-Lock: sha1:X2P2yJjRZKVPuNT4PiWA89nG8hE= Xref: news2.google.com comp.lang.ada:14199 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Date: 2011-10-27T09:12:44+02:00 List-Id: Wow congrats! To me this is impressive. And having these patches available in some place is definitely great. Alex. 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 ;). >