Creating Android apps using Chicken Scheme

1 Objective

To setup a toolchain to allow apps to be developed on a linux laptop and run/debug on Android.

2 Links and references

2.1 Chicken Scheme for Android

3 Environment setup

3.1 Before starting

Java SDK installed Android SDK installed Android NDK installed

3.2 Chicken Scheme installation

On Ubuntu 14.04 Chicken scheme is installed using:

sudo apt-get install chicken-bin libchicken-dev

4 Create Chicken-Android cross compiler

  1. Create copy of android-chicken makefiles using:
cd ~/projects/chicken/
git clone https://github.com/chicken-mobile/android-chicken.git
  1. Rename the default-config.mk file to config.mk and edit
  2. make

..however gives the following error:

stuart@stuart-1001PXD:~/projects/chicken/android-chicken$ make
cd src/chicken-core; git pull
Already up-to-date.
mkdir -p toolchain/android-14 && \
	/usr/local/android-ndk-r10e/build/tools/make-standalone-toolchain.sh \
	  --platform=android-14 \
	  --system=linux-x86_64 \
	  --install-dir=toolchain/android-14
WARNING: The shell running this script isn't bash.  Although we try to avoid bashism in scripts, things can happen.
Unable to auto-config arch from toolchain 
make: *** [toolchain/android-14/COPYING] Error 1

Web search found this SO article which suggests adding a –toolchain= option. http://stackoverflow.com/questions/29444079/unable-to-auto-config-arch-from-toolchain However, the error message suggests that the build script is trying to auto-config the architecture (and I'm guessing thats why the toolchain option is failing)

4.1 Theory 1 - check Android NDK and SDK have same platform as defined in config.mk

The config.mk file (edited from the default-config.mk file) has ANDROIDPLATFORM set to android-14. The Android NDK has the following platforms installed:

stuart@stuart-1001PXD:/usr/local/android-ndk-r10e$ ls -l platforms
total 56
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-12
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-13
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-14
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-15
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-16
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-17
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-18
drwxr-xr-x 5 root root 4096 Oct 28  2013 android-19
drwxr-xr-x 8 root root 4096 Oct  6  2014 android-21
drwxr-xr-x 3 root root 4096 Feb  2  2015 android-3
drwxr-xr-x 3 root root 4096 Feb  2  2015 android-4
drwxr-xr-x 3 root root 4096 Feb  2  2015 android-5
drwxr-xr-x 3 root root 4096 Feb  2  2015 android-8
drwxr-xr-x 5 root root 4096 Feb  2  2015 android-9

Where the Android SDK has the following platforms:

stuart@stuart-1001PXD:/usr/local/android-sdk-linux$ ls -l platforms
total 4
drwxrwxr-x 6 stuart stuart 4096 Mar  3 15:31 android-23

So.. config specifies android-14 but that is not installed in the SDK. Install using the android command to run the Android SDK Manager.. ..only to discover that API-14 is Android 4.0 which is OBSOLETE! ..So, I installed SDK API-21 (Android 5.0.1) which is the most up-to-date in the NDK

However, this did not solve the problem! (although probably the right thing to do anyway)

4.2 Theory 2 - debug the Makefile

Looking at the Makefile, the error is being reported from the call the the make-standalone-toolchain.sh script (which is part of the NDK). Examining the source, the error is caused by a TOOLCHAIN variable that isnt being set by a –toolchain= command line option.

NOTE: That I tried this previously but it dod not work because I forgot the \ newline char!!

The android-chicken Makefile does not set the toolchain option, so I added a TOOLCHAIN definition to config.mk (the toolchain should be in $(NDK)/toolchains/)

TOOLCHAIN         ?= arm-linux-androideabi-4.9

With this TOOLCHAIN definition in config.mk and a –toolchain=\((TOOLCHAIN) added to Makefile toolchain/\)(ANDROIDPLATFORM)/COPYING target.

SUCCESS!!

The make command now builds the android-chicken source.

5 Compile a Demo program

Using the Demo program (linked from the android-chicken documentation):

https://github.com/bevuta/example

git clone the repo

5.0.1 Install the dependent scheme modules (eggs)

The first to be installed is JNI using the command

android-chicken/build/host/bin/android-chicken-install jni

This failed with a message requiring the JAVAHOME environment variable needing set.

OOPS! No JDK installed??? Ok, follow instructions here: http://tecadmin.net/install-oracle-java-8-jdk-8-ubuntu-via-ppa/

TL;DR

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
$ sudo apt-get install oracle-java8-set-default

NOTE: that the last command doesnt set the JAVAHOME variable for me! so added with

export JAVAHOME=/usr/lib/jvm/java-8-oracle

This fixed the egg install problem. Continue installation of eggs with 'android-chicken-install jni' command.

5.1 Side-Project: Create APK after NDK build

To step back from the Android-Chicken head-off-wall-experience and maybe shed some light on the build issues, I decided to build one of the NDK Sample programs (hello-jni)

See this article which was helpful: http://blog.beuc.net/posts/Building_Android_NDK_samples/

Steps:

  1. install some of the 'missing' 32-bit libraries
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
  1. copy the sample programs into home directory space
  2. turn the directory into a project using the command
android update project --name "hello-jni" --path . --target "android-21"
  1. create a debug image (avoids signing) using 'ant debug'
  2. transfer the apk file to the device using 'adb install <file>.apk'

Author: Stuart

Created: 2016-07-10 Sun 15:04

Validate