Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Hoping for a really simple tutorial on creating native plugins...
Started by richard11 Nov 14 2018 08:53 AM

33 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

This seems the most appropriate forum to ask this, as I'm feeling beyond "newbie" right now!

 

In a nutshell, since Corona doesn't do camera preview as standard for Android (The fill method is iOS only) but the Android API does ( https://developer.android.com/guide/topics/media/camera#camera-preview ), I figured it's time to learn Corona Native and re-learn Java...

 

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.



[TOPIC: post.html]
#2

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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?



[TOPIC: post.html]
#3

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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...



[TOPIC: post.html]
#4

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

Hello! You almost figured it out, good job!

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.



[TOPIC: post.html]
#5

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

Brilliant, thanks. I'm not at my computer at the moment but I'll see if this works in the morning!

How do I manually launch tasks though?

[TOPIC: post.html]
#6

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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?



[TOPIC: post.html]
#7

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

This is where things are getting complicated. You can not run a plugin like that. For now you have several options:

1. Package a plugin and submit it to marketplace. For that you'll have to write a little documentation on how to use your plugin and why it's useful

2. Package your app as Native app, then you don't have to export a plugin - you'll have to integrate rest of the plugins into you Android Studio project

3. Get Self-Hosted subscription which allows you to side-load plugins into simulator builds.

 

This way you can choose to support Corona's ecosystem, Corona directly, or do it yourself. If you have more questions you can PM me or write here.



[TOPIC: post.html]
#8

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

Hmm...

 

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!



[TOPIC: post.html]
#9

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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?



[TOPIC: post.html]
#10

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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)
 
I guess this isn't the right way to test then?


[TOPIC: post.html]
#11

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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...



[TOPIC: post.html]
#12

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

Try using latest version of Corona, and copy new template app. Since you don't have much changes it would be easiest way to go.

Then transfer your changes to plugin/src ...



[TOPIC: post.html]
#13

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

Gahh, I didn't get chance to give that a try this evening. Will report back in the morning, thanks!

[TOPIC: post.html]
#14

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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...



[TOPIC: post.html]
#15

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

This is confusing. Do you get splash screen error when just running a template app without any modifications?

[TOPIC: post.html]
#16

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

Trying now. I'll document as I go...

 

- 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.



[TOPIC: post.html]
#17

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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.



[TOPIC: post.html]
#18

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

There’s obviously something bad going on :( let me investigate.

[TOPIC: post.html]
#19

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

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.

[TOPIC: post.html]
#20

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

You’re on Mac, right? If so, make sure to run Setup Corona Native from Native folder

[TOPIC: post.html]
#21

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

No, Windows. I haven't run any setup though... Did I skip a major step? 😁

[TOPIC: post.html]
#22

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

No, you’re good. But Windows explains differences between my and your experience.

[TOPIC: post.html]
#23

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

Also seeing "warning: CoronaBuilder: Splash Screen Control plugin not found" during the build phase, which I've been disregarding since I'm not trying to replace the splash... is it that Corona Native requires purchasing this plugin? We'll actually be doing so anyway towards the end of building this particular project, as it's for a client, but since it's an annual fee we wanted to hold out until we're ready for release!



[TOPIC: post.html]
#24

vlads

[GLOBAL: userInfoPane.html]
vlads
  • Contributor

  • 577 posts
  • Corona Staff

It seems that splash screen is broken on windows.

[TOPIC: post.html]
#25

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 242 posts
  • Corona SDK

Bummer, but at least I'm not doing something wrong!

I've put together a tutorial that concatenates everything I've read / figured out to get to this stage, as it didn't seem like anything existed as a single, concise piece. Since everything seems to work and I now know that the splash error is a bug with the current builds, I'll tidy this up and post a link here tomorrow. Hope it's useful to others, and thanks for your help in getting there.

Any idea when the splash will be fixed please?
  • Michael Flad likes this


[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]