Skip to content

Commit

Permalink
Handle Java 1.6 vs 1.7 automatically
Browse files Browse the repository at this point in the history
Better readme, update for SDK 17
  • Loading branch information
abarbu committed Jul 21, 2013
1 parent 186b3b3 commit 3656e60
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 59 deletions.
1 change: 1 addition & 0 deletions KawaHello/libs/kawa.jar
1 change: 1 addition & 0 deletions LearningAndroid-chapter10/libs/kawa.jar
1 change: 1 addition & 0 deletions LearningAndroid-chapter6/libs/kawa.jar
1 change: 1 addition & 0 deletions LearningAndroid-chapter7/libs/kawa.jar
1 change: 1 addition & 0 deletions LearningAndroid-chapter8/libs/kawa.jar
1 change: 1 addition & 0 deletions LearningAndroid-chapter9/libs/kawa.jar
1 change: 1 addition & 0 deletions LunarLander/libs/kawa.jar
65 changes: 34 additions & 31 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ distribution's package management software will help with this. Once
you're done, run /android/, select and install the latest API
revision (17 as of this document).

You will need Java 1.6, dex is unhappy with 1.7. Running
#+BEGIN_SRC sh
javac -version
#+END_SRC
should yield something that starts with 1.6, if not you're going to
have to use your distribution's package manager to switch to Java 1.6.

To get started with Scheme you'll need a custom build for Kawa, this
will fetch and build the latest sources
#+BEGIN_SRC sh
bin/setup-kawa <android-home> <android-platform>
#+END_SRC

You'll need to point it to your android SDK directory and give it the
platform number. On my machine this looks like:
#+BEGIN_SRC sh
Expand Down Expand Up @@ -54,39 +48,46 @@ or for example uninstall it you would use the package name, for example
adb uninstall kawa.example
#+END_SRC

Before we can run anything you'll need to either connect a phone with
developer mode enabled or set up an emulator. We can do the latter
with
*** Running on the phone

Building and running are both done by the same script.
#+BEGIN_SRC sh
cd SpeedRead && ./make-and-send
#+END_SRC
This will create an apk and send it out to the phone and run it. When
you modify the code just rerun make-and-send. Your first compile will
likely be slow but subsequent ones will be much faster. When you're
done you can clean up with
#+BEGIN_SRC sh
adb uninstall zeroxab.speedread
#+END_SRC

*** Running in the emulator

You first need to set up the emulator by running
#+BEGIN_SRC sh
android create avd -a -n Test -t 1 --abi armeabi-v7a
#+END_SRC
and just accept the defaults. If you've got a plain-vanilla SDK setup
id 1 will be the basic android platform. You can check with /android
list targets/ and adjust accordingly. Once it's setup it, just run
and accepting the defaults. If you've got a plain-vanilla SDK setup id
1 will be the basic android platform. You can check with /android list
targets/ and adjust accordingly. Once it's setup it, just run
#+BEGIN_SRC sh
bin/start-emulator
#+END_SRC
to fire it up, it'll take a while... The emulator is so obscenely
slow that you'll want to either run things on your phone or set up
vmware.

Once the emulator is up and running lets take our new project out for
a spin
#+BEGIN_SRC sh
cd HelloWorld && ./make-and-send
#+END_SRC
This will create an apk and send it out to either an emulator that
we're already running or to a phone we've connected. When you modify
the code just rerun make-and-send.
Running and building work the same way they do for the phone from the
same /make-and-send/ script.

*** Debugging

While debugging I have
#+BEGIN_SRC sh
bin/colorize-adb-logcat
#+END_SRC
running in a terminal to easily spot log messages. I haven't yet
bothered figuring out how to set up a debugger.
running in a terminal to easily spot log messages.

*** XML sanity

Expand Down Expand Up @@ -138,16 +139,12 @@ quirks. All examples try to mostly stay true to their source however
badly designed that source was. As such this isn't a good place to
look for good Scheme style or idiomatic Kawa.

To get the examples to work you need to set them up
#+BEGIN_SRC sh
bin/setup-examples
#+END_SRC
In general these are meant to be read, not necessarily run as such I
don't always keep them up to date.

You may need to update local.properties in each of the examples
directory to change the path to the Android SDK.

This has been tested with Android SDK r15 and r17.

LearningAndroid examples need to a copy of jtwitter.jar and
signpost-core-1.2.1.1.jar from
http://www.winterwell.com/software/jtwitter.php in each of their libs
Expand Down Expand Up @@ -204,9 +201,11 @@ hand by casting it explicitly.
#+END_SRC
*** no known slot '...' in java.lang.Object
As above, Kawa can't figure out the type of the object you're trying
to use and at some point ended up casting it to Object. Likely you've
to use and at some point ended up casting it to Object. Vou've
got something like a function or let binding where you didn't specify
a type. You can either do that or cast as in the above section.
a type. You can either specify one or cast as in the above section.

((lunarView:getThread):pause)

This might also happen if you have a misspelled identifier.
*** no possibly applicable method '<init>/valueOf' in ...
Expand All @@ -215,3 +214,7 @@ You've got code like
(make <something> args ...)
#+END_SRC
and one of the arguments is of the wrong type.
*** Unfortunately, <application name> has stopped.
Run 'adb logcat' or 'bin/colorize-adb-logcat' and have a look at the
RuntimeException. Right now there's no interactive debugger but one is
in the pipeline.
1 change: 1 addition & 0 deletions SpeedRead/libs/kawa.jar
8 changes: 4 additions & 4 deletions bin/make-project
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ NAME=$2
ACTIVITY=$3
PKG=$4

android create project --target ${TARGET} --name ${NAME} --activity ${ACTIVITY} --path ${NAME} --package ${PKG}
android create project --target ${TARGET} --name ${NAME} --activity ${ACTIVITY} --path ${NAME} --package ${PKG} > /dev/null || (echo "Failed to create an android project! File a bug at github.com/abarbu/android-kawa" && exit 1)
rm -f ${NAME}/src/${PKG_PATH}/${ACTIVITY}.jar
touch ${NAME}/src/${PKG_PATH}/${ACTIVITY}.scm
ln -s `pwd`/kawa/kawa-1.*.jar ${NAME}/libs/kawa.jar

cat > ${NAME}/build.xml.patch <<EOF
(cd ${NAME}; (patch -p0 <<\EOF
--- build.xml.orig 2010-10-11 15:48:59.092681778 -0700
+++ build.xml 2010-11-04 22:26:34.565673740 -0700
@@ -64,4 +64,27 @@
Expand Down Expand Up @@ -67,8 +67,8 @@ cat > ${NAME}/build.xml.patch <<EOF
+
</project>
EOF

(cd ${NAME}; patch < build.xml.patch)
) > /dev/null \
|| (echo "Failed to patch the build file! File a bug at github.com/abarbu/android-kawa" && exit 1))
echo "adb shell kill \$(adb shell ps|grep -i ${PKG}|awk '{ print $2 }') > /dev/null" > ${NAME}/make-and-send
echo "ant debug && adb install -r bin/${NAME}-debug.apk && adb shell am start -a android.intent.action.MAIN ${PKG}/.${ACTIVITY}" >> ${NAME}/make-and-send
chmod +x ${NAME}/make-and-send
Expand Down
15 changes: 0 additions & 15 deletions bin/setup-examples

This file was deleted.

45 changes: 36 additions & 9 deletions bin/setup-kawa
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

set -e
set -o pipefail

EXPECTED_ARGS=2
E_BADARGS=65
Expand All @@ -10,16 +11,10 @@ KAWA_VERSION=1.13
if [ $# -lt $EXPECTED_ARGS ]; then
echo "Usage: `basename $0` android-home android-platform"
echo " Setup a Kawa install in the current directory for a particular Android version."
echo " for example: bin/setup-kawa /opt/android-sdk-update-manager android-14"
echo " for example: bin/setup-kawa /opt/android-sdk-update-manager android-17"
exit $E_BADARGS
fi

if [[ -z $(javac -version 2>&1 | grep 1.6) ]]; then
echo "Your javac is not version 1.6.*"
echo " dex can't process files from any other version, you'll need to downgrade"
exit
fi

echo "Fetching Kawa ${KAWA_VERSION}"
if [ -e kawa ]; then
rm -r kawa
Expand All @@ -30,8 +25,40 @@ fi
tar xvf kawa-1.13.tar.gz
mv kawa-${KAWA_VERSION} kawa
cd kawa
echo "Patching kawa"
patch -p0 <<\EOF
--- Makefile.am.orig 2013-07-17 09:36:47.448268287 -0400
+++ Makefile.am 2012-11-22 02:11:40.000000000 -0500
@@ -258,7 +258,7 @@
COMMENT_OUT = s|^\([[:space:]]*\)\([^/[:space:]]\)|\1// \2|
gnu/kawa/util/PreProcess.class: $(srcdir)/gnu/kawa/util/PreProcess.java
- $(JAVAC) -d . $(srcdir)/gnu/kawa/util/PreProcess.java
+ $(JAVAC) -d . $(JAVACFLAGS) $(srcdir)/gnu/kawa/util/PreProcess.java
# JDK 1.1
select-java1: $(srcdir)/patch-source-list gnu/kawa/util/PreProcess.class
EOF
patch -p0 <<\EOF
--- Makefile.in.orig 2013-07-17 09:36:49.229268472 -0400
+++ Makefile.in 2012-12-09 02:29:46.000000000 -0500
@@ -959,7 +959,7 @@
| sed -e 's|./||' | sort > $@
gnu/kawa/util/PreProcess.class: $(srcdir)/gnu/kawa/util/PreProcess.java
- $(JAVAC) -d . $(srcdir)/gnu/kawa/util/PreProcess.java
+ $(JAVAC) -d . $(JAVACFLAGS) $(srcdir)/gnu/kawa/util/PreProcess.java
# JDK 1.1
select-java1: $(srcdir)/patch-source-list gnu/kawa/util/PreProcess.class
EOF
echo "Building kawa"
./configure --with-android=$1/platforms/$2/android.jar --disable-xquery --disable-jemacs
JAVACFLAGS="-source 1.6 -target 1.6" ./configure --with-android=$1/platforms/$2/android.jar --disable-xquery --disable-jemacs || (echo "Failed to configure Kawa!"; exit 1)
# Because kawa docs sometimes fail to build.
echo '' > doc/kawa.texi
make
make || (echo "Failed to build Kawa!"; exit 1)
cd ..
rm kawa-1.13.tar.gz
ln -s `pwd`/kawa/kawa-1.*.jar kawa/kawa.jar
echo
echo "Done! We're good to go"

0 comments on commit 3656e60

Please sign in to comment.