This guide explains how a Corona Enterprise for Android project fits together.
The following elements apply to a Corona Enterprise project:
android/app/build.gradle
— This is the main build script and it's also where you set up some application settings like version and what SDK versions to use.android/app/src/main/AndroidManifest.xml
— This is where you configure application settings such as name, permissions, etc.android/app/libs/
— This is where .jar
plugins that your app relies upon should go.android/app/src/main/jniLibs/
— This is where .so
plugins that your app relies upon should go.android/app/src/main/java/
— This is where the Java source files for your app should go. Because the package is com.mycompany.app
, this is where the files are located by default. You should modify this according to the package name you specify.Corona/
— A normal Corona project consists of your Lua files such as main.lua
, along with additional resource files like images, audio, video, etc. By default, build.gradle (Module: App)
Corona
that sits alongside the android
folder.For plugins, there are additional files and directories of interest:
android/plugin/build.gradle
— This is the build script that creates the plugin. The output is a .jar
file. The only files included in the .jar
are those located in plugin/src/main/
, whether they are code or resources.android/plugin/src/main/AndroidManifest.xml
— This is where you set up the plugin's package name.android/plugin/libs/
— This is where .jar
plugins that your plugin relies upon should go.android/plugin/src/main/jniLibs/
— This is where .so
plugins that your plugin relies upon should go.android/plugin/src/main/java/plugin/library/LuaLoader.java
— This is the code for the Lua library plugin.library
on the Android side.This brief walkthrough outlines the flow of the CoronaEnterprise/ProjectTemplates/App/
project for Android:
android/app/src/main/java/com/mycompany/app/CoronaApplication.java
At launch time, CoronaApplication.java
is instantiated. It adds a private class to be notified of various
Right before main.lua
is invoked, the onCreate()
method is invoked. At this point, OpenGL is set up and all Corona frameworks are available.
Corona/main.lua
In the Lua code, plugin.library
is loaded via require()
. The Corona engine will then look for a corresponding Java class called plugin.library.LuaLoader
and invoke it. The name of this class is dynamic and is constructed using the original library name passed to require()
as the package name for a LuaLoader
class. The LuaLoader
class is expected to implement the JNLua interface com.naef.jnlua.JavaFunction
.
android/plugin/src/main/java/plugin/library/LuaLoader.java
When the fully-qualified class path for LuaLoader
is resolved, the class is instantiated with the default constructor. The invoke()
method is then called by Lua via JNLua and does all the heavy lifting, for example creating the Lua library table, registering the Lua methods like show()
, and then leaving the table at the top of the Lua stack.
The LuaLoader
class is instantiated once for the lifetime of the process, much like a .dll
or .so
file is typically loaded once for the lifetime of the process.
The invoke()
method is called once for each Lua state that does a require()
. This corresponds to being called once each time the CoronaActivity
is instantiated.