diff --git a/KawaHello/libs/kawa.jar b/KawaHello/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/KawaHello/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/LearningAndroid-chapter10/libs/kawa.jar b/LearningAndroid-chapter10/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/LearningAndroid-chapter10/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/LearningAndroid-chapter6/libs/kawa.jar b/LearningAndroid-chapter6/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/LearningAndroid-chapter6/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/LearningAndroid-chapter7/libs/kawa.jar b/LearningAndroid-chapter7/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/LearningAndroid-chapter7/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/LearningAndroid-chapter8/libs/kawa.jar b/LearningAndroid-chapter8/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/LearningAndroid-chapter8/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/LearningAndroid-chapter9/libs/kawa.jar b/LearningAndroid-chapter9/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/LearningAndroid-chapter9/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/LunarLander/libs/kawa.jar b/LunarLander/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/LunarLander/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/README.org b/README.org index b611cb7..e332e75 100644 --- a/README.org +++ b/README.org @@ -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 #+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 @@ -54,15 +48,29 @@ 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 @@ -70,14 +78,8 @@ 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 @@ -85,8 +87,7 @@ 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 @@ -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 @@ -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 '/valueOf' in ... @@ -215,3 +214,7 @@ You've got code like (make args ...) #+END_SRC and one of the arguments is of the wrong type. +*** Unfortunately, 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. diff --git a/SpeedRead/libs/kawa.jar b/SpeedRead/libs/kawa.jar new file mode 120000 index 0000000..9f94aa3 --- /dev/null +++ b/SpeedRead/libs/kawa.jar @@ -0,0 +1 @@ +../../kawa/kawa.jar \ No newline at end of file diff --git a/bin/make-project b/bin/make-project index d66e36c..da4c14f 100755 --- a/bin/make-project +++ b/bin/make-project @@ -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 < ${NAME}/build.xml.patch < 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 diff --git a/bin/setup-examples b/bin/setup-examples deleted file mode 100755 index d2f1220..0000000 --- a/bin/setup-examples +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -if [ ! -d kawa ]; then - echo "Error: Kawa should exist in the kawa/ directory as set up by bin/setup-kawa." - exit 1; -fi - -ln -s `pwd`/kawa/kawa-1.*.jar KawaHello/libs/kawa.jar -ln -s `pwd`/kawa/kawa-1.*.jar LearningAndroid-chapter10/libs/kawa.jar -ln -s `pwd`/kawa/kawa-1.*.jar LearningAndroid-chapter6/libs/kawa.jar -ln -s `pwd`/kawa/kawa-1.*.jar LearningAndroid-chapter7/libs/kawa.jar -ln -s `pwd`/kawa/kawa-1.*.jar LearningAndroid-chapter8/libs/kawa.jar -ln -s `pwd`/kawa/kawa-1.*.jar LearningAndroid-chapter9/libs/kawa.jar -ln -s `pwd`/kawa/kawa-1.*.jar LunarLander/libs/kawa.jar -ln -s `pwd`/kawa/kawa-1.*.jar SpeedRead/libs/kawa.jar diff --git a/bin/setup-kawa b/bin/setup-kawa index f67bbda..25c5405 100755 --- a/bin/setup-kawa +++ b/bin/setup-kawa @@ -1,6 +1,7 @@ #!/bin/bash set -e +set -o pipefail EXPECTED_ARGS=2 E_BADARGS=65 @@ -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 @@ -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"