This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Updated Hello World tutorial & more general Kawa xml file for Android


Hi,

This is my first email to this list so let me first thank Per and all
the contributors for their work on Kawa.

I recently wrote a detailed guide on how to get Kawa working with
Android on Windows (though it wouldn't be too hard to use it for
*nixes) that you can find here:
http://asieno.com/blog/index.php/post/2012/08/16/Setting-up-the-environment-Android-Kawa

Most of it is probably of little interest to you guys but the thing
that might interest you is my spin on the build.xml patch from Per's
blog post of 2010 and Marius Kjeldahl's updating of it.

First, since the current Android SDK creates a build.xml file in the
project's root that optionally imports a custom_rules.xml file in the
same directory I changed it from a patch to a custom_rules.xml file
that you can find here:
http://www.asieno.com/files/programming/android/toolbox/custom_rules.xml

If you want to know/understand what modifications I did keep reading,
otherwise just plug that file in your new Kawa Android project's root
and you don't even have to modify it to use your project's package
name or activity name. Now for a detailed explanation:

Putting it in its own file meant that I had to surround it with a <project> tag:

<?xml version="1.0" encoding="UTF-8"?>
<project name="kawa_rules" default="help">
...
</project>

I also changed the scompile dependency to -code-gen as per Marius'
version to get it up to date with current Android build.xml targets.

These two changes bring the functionality up to Per's version for
current Android SDK but with less risk of the change getting
overwritten.

Then I was unhappy with using the -compile dependency for the -dex
target as it overwrites the one in the SDK's build.xml so I replaced
it with a dependency on the original -dex target (which itself calls
-compile): <target name="-dex" depends="android_rules.-dex, scompile">
...

It shouldn't make any difference unless you also use -post-compile or
-obfuscate and it probably means that we can get rid of the
<dex-helper> as it is called by the original -dex (my HelloKawa
project builds properly with it commented out) but as I don't know
much about ant I prefer to add rather than remove unless i am sure of
what I am doing.

I also was unhappy with the hard coded -P parameter given to Kawa as
well as the hardcoded .scm file path and name and wanted to generate
it from the AndroidManifes.xml file so I would only have to drop the
custom_rules.xml file in my project without having to edit it and it
would work.

Luckily a bit of googling found this question at stackoverflow:
http://stackoverflow.com/questions/10181394/using-androidmanifest-xml-version-code-in-ant
where the respondent mentioned that Android has a custom ant task
called xpath to do just that. A bit of searching in the SDK's
build.xml to understand how it works and i was able to add two lines:
      <xpath input="${manifest.abs.file}"
expression="/manifest/application/activity/@android:name"
output="android.activity.name" />
      <propertybyreplace name="project.app.package.path"
input="${project.app.package}" replace="." with="/" />

The first one gets the name of the first activity in the Manifest and
puts it in an ant variable called android.activity.name and the second
one uses the already defined project.app.package variable and replaces
its "." separators with "/" separators (I lifted it straight from the
SDK build.xml file to put it in a visible scope).

The only drawback is that the Scheme filename that needs to be given
to Kawa needs to be the name of the first activity defined in the
Manifest.

This allowed me to change "-P kawa.android. ..."  to "-P ${project.app.package}.
As well as change "src/kawa/android/hello.scm" to
"src/${project.app.package.path}/${android.activity.name}.scm"

That way everything works when creating the project, when updating the
SDK (as long as it keeps importing custom_rules.xml) or when changing
the project's package or main activity's name without having to lift a
finger.

I hope it will be useful for you guys and make your life a bit easier.

So the question now is, do any of you with more substantial Android
projects have any ideas how to improve it to make it even easier to
use Kawa with Android?

Ok, I'm off to Yoga & then beers so I'll check tomorrow for suggestions.

--
"I do not suffer from insanity... I enjoy every minute of it"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]