The Sling programming language and the Sling compiler can be used to develop cross-platform software for many different platforms, including Android. Since the compiler works by translating the Sling source code to Java code in the case of Android, the Android development tools are required to compile this code. This document is meant to help you in the installation and configuration of those tools for use with Sling.

Filed under

This document will outline the steps required for installing the different tools we need for developing Android applications using Sling.

Java Development Kit (JDK)

The Java Development Kit (JDK) is a software development toolkit used for developing Java applications. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), and other tools needed in Java development.

You should have downloaded and installed the latest Java Development Kit (JDK) from the official Java download site of Oracle:

Follow the standard installation instructions for your platform. To confirm that your installation was sucessful, open your command line terminal after completing the installation and execute the following command:

javac -version

This should tell you the Java Development Kit (JDK) version you are using. It should look somewhat like the following (depending on the actual version that you have installed):

javac 1.8.0_131

Android SDK

The Android SDK (software development kit) is a set of development tools from Google used to develop applications for the Android platform. Download the Android SDK from the following location:

The Android SDK can be downloaded separately as a stand alone installer, or as part of the bigger Android Studio installer. Follow the standard installation instructions.

Gradle

Gradle is a popular open-source build automation tool for Java, particularly used for Android development. For use with the current versions of Android SDK and slingc, we should use Gradle version 3.5.1. You can download it from here:

Once downloaded, unzip the file. For the gradle executable to be automatically discovered, it needs to be in the operating system PATH. Please see below for system-specific instructions for setting that up.

Linux & MacOS users

Configure your PATH environment variable to include the bin directory of gradle, e.g.:

$ export PATH="<path-to-unzipped-gradle-directory>/bin:$PATH"

Microsoft Windows users

In File Explorer right-click on the This PC (or Computer) icon, then select Properties -> Advanced System Settings -> Environment Variables. Then under System Variables, select Path and choose Edit. Add an entry for gradle, e.g:

<path-to-unzipped-gradle-directory>\bin

Click OK to save.

Verification

To verify your installation and configuration, open your command line terminal and execute the following command to run gradle and display the version, e.g.:

gradle -v

As part of the output, you should be able to see this:

Gradle 3.5.1

Eqela Runtime

The Eqela Runtime is used to execute the Sling compiler and any other tools for compiling Sling programs. If you have not yet done so, install Eqela Runtime through the link below:

After installation, open your command line terminal and execute this command:

eqela

You should see something like the following:

Eqela Runtime / 5.0.1 @ .NET Core / C#
Copyright (c) 2018 Eqela Oy
Licensed under GPLv3 (see LICENSE for details)
...

This tells you that your installation was successful.

Compiling a Sling project

For the sake of example, create a new directory named slingandroid. Inside this newly created directory, create the following two files:

this.pling

// This is my application

MainWidget.sling

class #widget #main:

import cave.ui

ui LayerWidget
{
	LabelWidget myLabel {
		text = "Hello World"
	}
}

This is now a complete application that we can compile. To translate this application to an Android project, use the following command:

eqela eqela:slingbuild:r19 buildAndroid src=slingandroid

Assuming that this command executes successfully, you should now have a complete Android application project in the directory build/slingandroid/android/src. This now contains the source code of your application and the relevant parts of the Jkop framework in the Java programming language.

To now compile the Java source code to an Android installer (APK), you could of course open the project in Android Studio or any other tool that operates on Android projects. But Eqela also provides a convenient build tool, which you can use. Simply use the following command:

eqela eqela:rocks:r6/builder build/slingandroid/android/src/ -output=myappoutput -findCommandsInPath

If your encounter an error that says that the compiler was "Unable to find Android SDK", then you will need to specify the path to your SDK as follows:

eqela eqela:rocks:r6/builder build/slingandroid/android/src/ -output=myappoutput -findCommandsInPath -androidSdkPath=<path-to-androidSdk>

NOTE: In this case, you MUST replace the <path-to-androidSdk> with the actual path where you have installed your Android SDK.

NOTE: The Gradle path can also be specified using `-gradlePath=` parameter if you have not configured the gradle into your PATH environment variable as specified earlier.

You should find now the Android APK installer in the output directory specified (myappoutput in the sample command above).

Installing the APK file

If this is your first time to install the particular app on the device or emulator, using the sdk tools you can simply do this (this is assuming that your device is "Developer Mode" enabled):

<your android sdk directory>/platform-tools/adb install <your APK file>

To replace a previously installed app, the -r parameter of adb can be used.

<your android sdk directory>/platform-tools/adb install -r <your APK file>

Take note that the -r parameter means to replace an existing application .


Twitter Facebook LinkedIn Youtube Slideshare Github