I THINK I understand the general concept. Write native Android Java code, compile it as a .jar, and include that in as a regular plugin within a Lua project so that Lua can talk to Java methods and Java can do the native Android calls. Is that right?
Unfortunately it’s been a very, very long time since I did anything as native Android. Android Studio didn’t exist at the time (think I used Eclipse) and Gradle wasn’t a thing either.
Following https://docs.coronalabs.com/native/android/index.html I’ve installed Android Studio and copied the template folder. But beyond this, I’m lost. Google is just sending me around in circles and I’ve not yet even figured out how to rename the project in Android Studio, let alone where to start writing code.
Could somebody please point me in the direction of a suitable tutorial? If I can just get to a point where I’ve a Java class with a simple method that returns say, “hello world” to Lua, that would be brilliant.
I might be getting somewhere with this now (and I might throw together a tutorial to post back here if I am), but I can’t seem to build the jar file from within Android Studio - I’m just getting this when I try:
“JUnit version 3.8 or later expected”
Using the template that came with Corona SDK so presumably this should just work… Any pointers please?
Ah - I think that was because the run configuration wasn’t set to “app”. Skipped over this error now.
I don’t appear to be getting a .jar file when building though. In the build log, under the “Run tasks” section, there’s an amber icon with greyed out vertical lines overlaying it next to the “:plugin:exportPluginJar” task… Presumably that’s important…
Unfortunately plugin:exportPluginJar got broken with latest update of the Android Studio. You still can do it manually.
Launch “assembleRelease” task, after this go to plugin/build/outputs/aar/plugin-release/. Unzip plugin-release.aar (open it with unarchiver/7z/archieve utility). Inside a folder you’ll see plugin.jar. This is your plugin. Rename it to match your plugin name and you’re good.
OK, past that stage now - Tasks can be executed directly from the Gradle tab on the right, if anybody else stumbles onto this thread.
I have my .jar file now, and if I’ve done everything correctly it should contain a couple of simple methods waiting to be called - yay.
Seems I haven’t understood how to use this in a Lua project though. I expected I’d just copy it into a Lua project and require it like any other module, but this doesn’t work. What am I missing?
I’m obviously happy to submit to the marketplace once the plugin is complete, but if that’s the only way to execute then how do we test during the build?
Right now, my plugin doesn’t do anything even remotely useful. It essentially just responds with a “hello world” string when a method is called. Definitely not useful for the marketplace, and until I see it working, I don’t even know that I’ve built it properly!
Figured I’m supposed to use the Corona folder within the template for testing. Android Studio’s emulator doesn’t work on this laptop (It’s an AMD…) so I’d planned to just use Corona Simulator and the jar plugin for that… Probably a stupid idea =).
I’ve USB’d to an Android phone and modified the main.lua within this Corona folder to load my plugin instead of plugin.library (because I’ve already renamed it), and the build process seems to work, an APK is installed to my device which is presumably this Corona app, and the app tries to launch. It then just instantly closes though (I’ve made no other changes to the main.lua, and I’m seeing this in the logcat:
27134-27154/com.mycompany.app A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 27154 (GLThread 943)
First off - is the com.mycompany.app just what the test process calls it, or am I supposed to change that somewhere?
Secondly - would a segfault like this indicate I’ve broken something in the Java (understandable that this isn’t the right place for support with that side of things), or have I just stumbled down the wrong path again?
Semi-answered my own question. If I replace the entire contents of main.lua with a simple print(“test”) and don’t load the Java plugin in at all, I still get a segfault:
2018-11-16 16:21:45.222 1324-1402/com.mycompany.app I/Corona: This application failed to load and execute main.lua
2018-11-16 16:21:45.224 1324-1402/com.mycompany.app A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x8 in tid 1402 (GLThread 1054)
Ohhh… If I do a “clean” before running every time I make a change to main.lua, the segfault doesn’t happen. Getting somewhere!
Now seeing a “Incorrect splash screen” error though, and the app still closes immediately once this error is closed, BUT I’m also seeing the test message from my Java method! YES!
Any advice on the splash error please? I think if I can resolve this, I’ll be good to go…
I’ve installed the latest daily build, 2018.3437 (I was already on a daily build that was newer than the general release), copied over the template from this, and migrated my changes across. Still seeing “Incorrect splash screen - the splash screen built into the app is not the one that shipped with build 2018.3437 of Corona.” and the app then still closes itself…
Copied the App folder to a new location. Didn’t even rename it this time.
“Open existing Android Studio project” within Android Studio. Selected the android folder.
Pops up with a notice to update the Gradle plugin to version 3.2.1 and Gradle 4.6. Clicked “Update”.
Sync autoruns and completes with warnings that “The specified Android SDK Build Tools version (27.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1. Android SDK Build Tools 28.0.3 will be used.”. Clicked to update and sync.
Sync re-runs and completes.
Plug my phone in, a Samsung S8 running Android 8 (API 26), hit “run” and chose the S8.
Build completes. APK installs. Phone launches. The Dictionary.com page opens in the background so the show() method is being invoked properly, but the splash error pops up on screen and when I click OK, the app closes.
Hmm… having written all of that down I wonder if it’s because the phone is API 26 and the SDK is 28. I’ve also just noticed that the app\build.gradle has a targetSDKVersion of 27 which probably isn’t right… does this not want to be as low as possible? If 27 is the lowest we can get away with (for JNLua maybe?) then am I going to have problems with testing on an Android 8 device? I do have an Android 9 here too, but it’s not currently in developer mode is all.
Nope. Tried now with various SDK versions to no avail. Also tried with a new clone of the template, this time choosing not to update Gradle versions, and the same error occurs.
Thanks. I did a spot of Googling and found some old threads in these forums from people migrating out of Enterprise and getting the same error, if that helps. Seems some people worked around it by deleting the splash image but that didn’t seem to work for me either.