Ceda development on Android

Install Android Studio on Ubuntu

Run the following commands:


sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt update
sudo apt install ubuntu-make

Make sure the umake version is at least 16.05


umake --version

Install Android Studio


umake android

There will be a prompt for the installation path, probably ~/.local/share/umake/android/android-studio. Accept it.


Choose installation path: /home/user/.local/share/umake/android/android-studio

See How to install Android Studio on Ubuntu

Enable development on a real Android device

Development is typically more effective on a real Android device than a virtual (i.e. emulated) device.

If you connect a device without setting it up for development it won't typically show up as a device available in Android Studio

Use the following steps to allow development of applications on a real Android device:

Install the CEDA SDK for Linux development

As described under Ceda development on Linux, use the following steps to install the CEDA SDK, and the pyceda and pypizza python extension modules:

Install the CEDA SDK for Android development

There is a Android CEDA SDK specifically tailored for building CEDA based applications that run on Android devices.

Currently only the arm64-v8a platform is supported

Build the example pizza library for arm64-v8a

It is assumed the pizza example has been downloaded.

Run the build_pizza_library_android bash script to run Xcpp to translate the Xc++ files into straight C++:


cd ~/developer/pizza/Acme
./build_pizza_library_android

Build an example Android Studio project

  1. Download the tarball using this link: CedaAndroidExample-0.7.tar.gz (file size is 0.1 MB)

  2. Uncompress the CedaAndroidExample-0.7.tar.gz file using the following commands:

    
    mkdir ~/developer/CedaAndroidExample
    cd ~/developer/CedaAndroidExample
    tar -xvf ~/developer/CedaAndroidExample-0.7.tar.gz

  3. Run Android Studio and open the CedaAndroidExample project
  4. Make a folder jniLibs and copy the 10 CEDA SDK so files from ~/developer/ceda-android/lib/arm64-v8a/Release
  5. 
    cd ~/developer/CedaAndroidExample/app/src/main/ 
    mkdir -p jniLibs/arm64-v8a
    cp ~/developer/ceda-android/lib/arm64-v8a/Release/* jniLibs/arm64-v8a/
    
  6. Build and run on an Android arm64-v8a device

Enable writing to external storage

CEDA needs to be able to write a local database to external storage. See Saving Files on developer.android.com.

To write to the external storage, you must request the WRITE_EXTERNAL_STORAGE permission in your manifest file:

<manifest ...>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    ...
</manifest>

Path to database

A path to a CEDA database must be defined in a directory for which the Android application has permissions to read/write. For the above example a path of the form "/sdcard/temp/filename" has been used

Enable network socket connections

CEDA needs to be able to open network sockets. See Connecting to the Network on developer.android.com

In order to perform network operations in your application, your manifest must include the following permissions:

<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    ...
</manifest>

Register reflected CEDA data types

A JNI function needs to be written for initialisation purposes, that is called once by your Android application. This must call a function to register the CEDA reflected datatypes. This is mandatory for CEDA to work correctly

In the above example this involved the call to the following function:


extern "C" void Register_Project_Pizza();

Catch exceptions

It is a good idea for the JNI functions to use a try-catch block to catch exceptions thrown by the C++ code, to allow errors generated by CEDA to be displayed to help diagnose problems. I suggest these are logged so they appear in the Logcat window of Android Studio during development.






Build the ceda core libraries for Android

For core CEDA library developers here are the instructions for packaging the CEDA core libraries for targeting Android.