Create Android Native Plugin (Enterprise acct)

Hi All,

I have been trying to create a plugin for Corona using the Corona Enterprise. I want to be able to access functionality in a 3rd party JAR file from main.lua

I have followed all the documentation that i could get my hands on. I even tried to simply build the ‘App’ template but it couldn’t find the plugin.library. 

I have successfully built using ‘ant’ and got the plugin.library.jar. Then I tried to run the test app using the Corona Simulator but it throws an error saying that it couldn’t locate the plugin.library mentioned in the first line of the main.lua file “local Library = require(“plugin.library”)”

I do know what to write in the LuaLoader and I understand all the steps necessary to get the plugin done. I just can’t seem to have the simulator see the plugin.

Please help! If there’s a sample plugin (open source) that would be great, otherwise, i just need to know what I need to do to get it to run.

Thank you very much :-}

If this is a non Corona 3rd party jar file then it isn’t as straight forward as that.

You would need to use JNLua to bridge the Java functions contained the Jar file to Lua. You would essentially be creating a Plugin, that calls the methods from the Jar file and exposes them to Lua.

Because you see, the Java code knows about the Jar and its methods, but Lua does not

@Danny: Exactly! So that’s what I’m trying to do, create a plugin. The problem is that when I modify the LuaLoader.java and compile with ant, it exports the jar of the plugin. When I try to run the app which has the Library = require(“plugin.testlibrary”) i get the following error from the simulator :

File: module ‘plugin_testlibrary’ not found

Module ‘plugin_testlibrary’ not found:resource (plugin_testlibrary.lu) does not exist in archive

    no field package.preload[‘plugin_testlibrary’]

    no file ‘/Users/ed.khoury/Library/Application Support/Corona/Simulator/Plugins/plugin_testlibrary.lua’

    no file ‘/Users/ed.khoury/Android/Corona/TestPlugin/Corona/plugin_testlibrary.lua’

    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/plugin_testlibrary.lua’

    no file ‘/Users/ed.khoury/Library/Application Support/Corona/Simulator/Plugins/plugin_testlibrary.dylib’

    no file ‘./plugin_testlibrary.dylib’

    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/plugin_testlibrary.dylib’

so I don’t know what I’m doing wrong. It seems that I can’t create a Native Plugin for some reason. I’ve read all the documentation I can find but still I can’t get this to work. Any help you can provide will be greatly appreciated.

Thanks.

You cannot test the plugin you’re developing with the Corona Simulator.  This is because the Corona Simulator does cloud builds.  It gets its APK’s from our build servers which do *not* have a copy of your plugin.  And we do not want your plugin until you proved that it works.

So, this means that you’ll have to test your plugin/library the same way all native Android developers do it.  You’ll have to create a separate Android application project which references your library and build it locally.  You would reference your library just like any other, by either (1) copying it to the “libs” directory or (2) referencing your Android library project via the “project.properties” file.  How to do (1) or (2) is documented on Google’s Android developer website.  You would do so in the same manner as how the Facebook library or the AdMob library would be included.  Once your library is compiled into your test app (merged into a single Android *.dex file), Corona will then be able to find your plugin via Java reflection.

The easiest way to set up a test project for yourself is to make a copy of one of our Corona Enterprise sample projects under the “samples” directory.

If this is a non Corona 3rd party jar file then it isn’t as straight forward as that.

You would need to use JNLua to bridge the Java functions contained the Jar file to Lua. You would essentially be creating a Plugin, that calls the methods from the Jar file and exposes them to Lua.

Because you see, the Java code knows about the Jar and its methods, but Lua does not

@Danny: Exactly! So that’s what I’m trying to do, create a plugin. The problem is that when I modify the LuaLoader.java and compile with ant, it exports the jar of the plugin. When I try to run the app which has the Library = require(“plugin.testlibrary”) i get the following error from the simulator :

File: module ‘plugin_testlibrary’ not found

Module ‘plugin_testlibrary’ not found:resource (plugin_testlibrary.lu) does not exist in archive

    no field package.preload[‘plugin_testlibrary’]

    no file ‘/Users/ed.khoury/Library/Application Support/Corona/Simulator/Plugins/plugin_testlibrary.lua’

    no file ‘/Users/ed.khoury/Android/Corona/TestPlugin/Corona/plugin_testlibrary.lua’

    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/plugin_testlibrary.lua’

    no file ‘/Users/ed.khoury/Library/Application Support/Corona/Simulator/Plugins/plugin_testlibrary.dylib’

    no file ‘./plugin_testlibrary.dylib’

    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/plugin_testlibrary.dylib’

so I don’t know what I’m doing wrong. It seems that I can’t create a Native Plugin for some reason. I’ve read all the documentation I can find but still I can’t get this to work. Any help you can provide will be greatly appreciated.

Thanks.

You cannot test the plugin you’re developing with the Corona Simulator.  This is because the Corona Simulator does cloud builds.  It gets its APK’s from our build servers which do *not* have a copy of your plugin.  And we do not want your plugin until you proved that it works.

So, this means that you’ll have to test your plugin/library the same way all native Android developers do it.  You’ll have to create a separate Android application project which references your library and build it locally.  You would reference your library just like any other, by either (1) copying it to the “libs” directory or (2) referencing your Android library project via the “project.properties” file.  How to do (1) or (2) is documented on Google’s Android developer website.  You would do so in the same manner as how the Facebook library or the AdMob library would be included.  Once your library is compiled into your test app (merged into a single Android *.dex file), Corona will then be able to find your plugin via Java reflection.

The easiest way to set up a test project for yourself is to make a copy of one of our Corona Enterprise sample projects under the “samples” directory.