Today’s tutorial is an introduction to Corona Enterprise development on Android, showing Corona developers how to extend or create a Corona project that leverages native Android functionality. Using Enterprise, Corona developers can combine the best of both the native world and the rich feature set of Corona SDK. Sign up for a 30-day trial and get started today.

Note: If you’re interested in using Enterprise for iOS, see the iOS quickstart tutorial.

Setting Up

Enterprise for Android is a different environment than iOS. While you can use Eclipse as an IDE or the preview of the new Android Studio IDE, it may be easier to work from the command line and use the editor of your choice. This tutorial won’t discuss in detail how to use the command line, but it’s an essential skill to learn, especially for developing with Android.

At the minimum, you should become familiar with your computer’s file system (folder structure) and learn how to use the cd command. If it’s not already running, first open your Terminal application:

Applications → Utilities → Terminal

Here you’ll see the traditional $ prompt — this is where you’ll run various commands in this tutorial.

Install Corona Enterprise

First, install Corona Enterprise in the root Applications folder. Do not install it in a subfolder or elsewhere, as the product requires a specific linking association.


Install the Android Tools

If you’ve already been building Android apps for Corona SDK, you may have done some of this before, but it won’t hurt to repeat the process and get the latest updates from Google. Essentially, you need to install Google’s Android SDK and its tools. To do so, visit and click on the Download the SDK ADT Bundle for Mac button. On the next page, agree to the terms and click the download button. This will download a file with a name like

If your system does not automatically unzip this for you, double-click the file to unpack the archive. If you’ve done this in the past, it will suffix an extra number on the end like: adt-bundle-mac-x86_64 2 or adt-bundle-mac-x86_64-20140321. If this occurs, rename the file so that it’s just adt-bundle-mac-x86_64. You may need to remove the old version from your download folder first.

Move that entire folder to your home directory. This folder contains some files that you’ll want to access from the command line without typing the entire path each time. To facilitate this, you can tell your computer where to find them by creating a file in your home directory called .bash_profile. This is a hidden file and you cannot easily access it from the Finder. So, from the Terminal, type in these commands:

Reopen the Terminal at this point and run the android command. This should load the Android SDK Manager which looks similar to this:


From here, you’ll want to install several things including:

  • Android SDK Tools
  • Android SDK Platform-tools
  • Android SDK Build Tools (latest version)
  • Several of the Android n.n.n (API X) entries

Which Android SDK entries you need to install varies based on what you’re building. You should install Android 4.1.2 (API 16) since this is the current version that Corona SDK uses. You should also install the minimum SDK version that you want to support — for Corona SDK, this is Android 2.2 (API 8). Finally, you need to install the target and minimum SDK for any library that you plan to use. While it may seem easier to just install everything, these SDKs take up disk space and they also take time to download/unpack. If you download them all, expect a long wait.

Once you have the necessary items selected, click on the Install [n] packages… button. On the next screen, accept the license agreement(s) and sit back while everything installs. When the process is finished, close the Android SDK Manager and return to the Terminal command line.

App Signing

This may seem early in the process to talk about signing, but its good to understand how it impacts the overall process. Essentially, there are two types of Android apps: those signed for debugging purposes and those signed for release purposes. Apps signed with a debug keystore can be installed directly on devices but cannot be downloaded from stores. Apps destined for the marketplace require a release keystore which you may have already created for use with Corona SDK.

This tutorial assumes that you already have a release keystore and that you know the passwords for the keystore and the alias. If you haven’t yet created one, see the Signing for Release Build section of the Signing and Building — Android guide.

Preparing the Project

Let’s start by preparing the project. Because every Corona developer stores their projects in different locations, for example a folder called Corona in their Documents directory, or perhaps a folder named Projects in the home directory, it’s your responsibility to understand the command line path to this location. This tutorial assumes that you have a folder called Projects located inside your home directory.

From the Terminal, change directory to the folder where you want to create your project:

When you type in commands and you see a tilde (~), that indicates your home directory. As such, the above command places you in the Projects folder.

Next, let’s copy over some template files. The simple project in this tutorial will check if the device is currently connected to WiFi, so consider a project folder name like getWiFi. When you’ve decided, type the following command, substituting ./getWiFi for the folder path/name that you desire:

This command will copy the folder from /Applications/CoronaEnterprise/ProjectTemplates/App to the folder you specified. If this folder does not exist, the command will create it. You can also do this step visually within the Finder by simply copying the App folder from the /Applications/CoronaEnterprise/ProjectTemplates folder and renaming it to the name of your project.

There’s one last step to prepare your project — you need to change directory to the getWiFi/android folder and run a process to update the project.

Setting the Package Name

We’re all in the habit of naming our projects with a “reverse domain” name like com.yourcompanyname.yourapp. The template you copied uses the name, but if you plan to deploy this app, you need to change this as follows:

1. Rename Folders

Let’s start with renaming the folders inside the src folder. In Android native development, your source files are located here, however they’re also subdivided such that each part of your package name is another folder. For instance, if your package name is com.supercompany.getWiFi, your .java files will live inside:


However, the project template you copied uses this path:


You must rename each of these folders to match whatever you choose for your package name. If you don’t use .com for your package name, you’ll need to change the com to org, net, etc.

Assuming the sample above, make sure you’re in the project’s android folder and:

2. Edit the Java File

Next, open your favorite text editor and open the following file here:


Inside it, change the package line at the top to use your reversed package name of com.supercompany.getWiFi.

3. Edit the “AndroidManifest.xml” File

The last step in the package name process is editing the AndroidManifest.xml file:


Inside, there are several places where you must change to your package name. Be sure to check for all occurrences and change each one.

Also, look for both occurrences of android:label="App" and change them to the desired app name:


Finally, since this app needs extra permissions, you’ll need to specify it. Look for this line…

And add an additional permission below it…

The “build.xml” File

In the android folder under your main project, there’s also a build.xml file. Change this line…

To this…

To ensure that you’ve done everything correct, return to the Terminal and change directory up three levels to the android folder where the AndroidManifest.xml and build.xml files are:

Now type pwd (“print working directory”). The result in the Terminal should end in getWiFi/android.

There should be a file inside called — this is what you’ll use to compile your app. Type this command now:

If you’ve done everything right, your app should build with out error. You can verify this by looking inside the bin folder for a file named for your app with a -release-unsigned.apk extension, for example getWiFi-release-unsigned.apk. You can confirm with this command…

Which should yield a Terminal output similar to this…

Signing the App

At this point, you have a compiled Android app that doesn’t do much. It also has not been signed for either debug or release, and it’s unaligned. To correct this, you can run the following two lines, replacing the capitalized cues with your keystore details.

As you can see, the jarsigner command is complicated. Fortunately, the script also knows how to sign your app if you tell it where to find the keystore files.

To make your life easier, create a new file called This file should be created in the android folder (the same folder as build.xml and and it should contain two lines:

Of course, you must substitute your custom keystore details in these lines. Let’s say that you created your keystore named androidrelease.keystore with an alias of androidrelease and saved it in the Projects folder off of your home directory. In this case, the file would look like the following, with YOURHOMEDIR changed to your home directory.

Release or Debug Builds

If you want to swap between release and debug builds, the easiest approach is to duplicate the file and rename it Once duplicated, edit and change the bottom line from…

To this…

Then, you can run either build script depending on which type you want:

Installing the App

Now tether an Android device to your computer via its USB cable. This tutorial assumes that you’ve already set your device into Developer Mode, that you’re familiar with the adb command (guide), and that you successfully built the app using the method above. When ready, enter the command:

This should install the app on your device. Find it and run it, and — if you wish — monitor errors in the console log using the command:

Making it Interesting

At this point, you’ve built an empty app project template which does virtually nothing. Let’s add some functionality that you cannot do from within Corona SDK.

1. Edit “”

To begin, open the file located here:


Look for the following code starting around line 35…

Replace this code with…

To summarize: in this Java code, you’re working in a class called CoronaApplication which has a method called onLoaded(). This method is called after the Lua Runtime has been created but before your main.lua has executed. The com.naef.jnlua is the Lua class for Java.

This code block does four things:

  1. Get the current Lua state for communicating with Lua.
  2. Define a list of functions that Lua can execute.
  3. Define the library name that Lua will use to run your functions.
  4. Tell Lua to get those functions.

In this case, there’s one method that you’re making available: IsWiFiEnabled(). Then you register the library name "getWiFi" that you’ll use on the Lua side to access these features.

2. Create “”

Next, create a new Java file in the same folder named with this source:

The public class IsWiFiEnabled() line has to match what you put in the other Java file when defining the functions for Lua, and it’s case sensitive. Next, just below that, you define a function called getName(). This returns the name of the function that your Lua code will use. The combination of this, plus the library name in the file, will produce the call for Lua, in this case getWiFi.isWiFiEnabled().

The invoke method runs your native code. The first block gets the Corona activity. The next block of code accesses the WiFiManager object. The variable value is defaulted to false and if the WiFiManager says it’s enabled, that value is set to true. Then the value is pushed as a boolean onto the luaState stack, and this value will be returned to your Corona SDK code.

The Corona SDK Side

Because Corona Enterprise templates are set up with the assumption that you may want to build for multiple platforms, the Corona folder is a peer to the ios and android folders and is located here:


Inside you’ll find the Corona project. Open us the main.lua file and change it to match the following:

This creates a display.newText() object that shows the status of the WiFi. Every 2 seconds, the timer will fire, get the value of the getWiFi.isWiFiEnabled() function, and update the text string accordingly.

Now go to your Terminal and repeat the building, signing, and installation process. If everything is correct, it should run and you should see the string “Checking” show up on your device for a couple of seconds. Then it should update the string depending on the status of your WiFi connection.


Clearly this tutorial is just a basic example of what can be done with Corona Enterprise, but hopefully it has shown you what can be accomplished when you combine the nearly unlimited power of native programming with the ease and simplicity of Corona SDK.

See more here: 

Tutorial: Corona Enterprise Quickstart (Android)