Thanks Rob and agramonte.
I tried the Andorid native but even at start I get this error when trying to open through Android
Failed to generate resource.car
Is there a good video instruction how to start the native side?
Thanks Rob and agramonte.
I tried the Andorid native but even at start I get this error when trying to open through Android
Failed to generate resource.car
Is there a good video instruction how to start the native side?
My opinion only: All of it is not really Corona specific. You can search on youtube for how to build native android apps, get familiar with gradle, how jnilibs work in an android project, how to run extra scripts while building and the structure of a typical android project. Once you learn all that the structure and how the native build works will be easy to understand. All of the corona magic is inside a set of .so files the rest of the native build is standard android build stuff, a little code glue, and some scripts.
Getting away from all that is why I ended up in Corona and doing mostly Corona Simulator builds.
I know enough about android native. However, every android studio upgrade creates whole lot of issues that you rarely see in corona. I was hoping translation does all the muscle works.
So to develop native, you do as usual in corona and only access the classes? I imagine you can’t access objects at the same time in android and corona, is it correct?
You can send messages back and forth between Corona and the android side and then using those messages to appropriately modify objects on either side. But no you can’t, for example, change the color of an object in lua from the android side directly.
This tutorial is really, really old. It’s not based on our current Corona Native Android Studio builds, but the old Enterprise based ANT command line builds. This is one of the reasons this tutorial is not available on our site, but someone cloned it, so you still can access it:
http://www.sdknews.com/cross-platform/corona/tutorial-corona-enterprise-quickstart-android
Most of the tutorial isn’t going to be of any use to you at all, but if you scroll down to the “Do something interesting” section, that’s where you can find the actual Lua, Java and bridge code between that shows how to talk to native API’s from Lua. It’s a very simple example. You would of course still have to copy the latest App template package from the Corona/Native folder to your working project, update the AndroidManifest.XML and such in Android Studio.
The App project should work in up-to-date Android studios.
Rob
I tried it but I get this error on Windows 10.
Process ‘command ‘C:\Program Files (x86)\Corona Labs\Corona\Native\Corona\win\bin/CoronaBuilder.exe’’ finished with non-zero exit value 1
resulting in error:
ERROR: Failed to generate resource.car
I imagine there is access issue for the CoronaBuilder.exe.
no clue how you can get over this.
so technically, a corona app could be built in c++?
Greg
Greg, not really. If you want to call api calls like display.newImageRect(), you’re going to need to do that in Lua with at a minimum of a main.lua and config.lua. Anything that’s going to be part of the OpenGL hierarchy will have to go through the Corona C to Lua bridge and be done in the Lua side of things.
Corona Native lets you use Xcode or Android Studio to build apps without the simulator. You still have your Corona project which is going to be all of your Lua code. From there, if you want to do offline builds, you can with your 100% Corona/Lua code. Xcode/Android studio will take care of the packaging and code signing, linking in the Corona libraries etc. While there are benefits, in particular, if you don’t have a good network connect, to doing native builds, the Simulator using our build dialogs really makes things simple and generally faster to do builds.
CoronaBuilder is basically a command line tool that does the building for you. Basically, you can provide all of the build dialog parameters on the command line. Again, most people don’t want to mess with life on the command line, but some people need to batch build multiple Corona apps and command line builds can save them time.
Now all that said, the other thing that Corona Native lets you do is twofold: 1. It lets you use some C++, Objective C, Swift or Java code with your Corona app. Let’s say you need to access some feature that Corona doesn’t support (like turning on the camera flash/LED). You can use Xcode/Android Studio, have your main Corona app and write some native code and create some functions that bridge them to Lua and you can then call those native functions from Lua. 2. Likewise, you can use similar technology to create a plugin (which has the native functionality and bridge code, but in a more portable method). If your plugin is useful enough, you can submit it to the Corona Marketplace for others to use. You can also purchase self-hosted plugins which lets you build plugins for yourself and use the Simulator for building.
Rob
Hi Rob,
To understand this, it is a Lua to C bridge, that converts the lua to C code? How about the conversion from C to java (Android) or C to objective C(Apple)? That is a second step in creating the apk?
I’m just curious, Greg
I guess I wasn’t clear enough. Your Lua code is never converted to C code. We embed a Lua interpreter in your package and your Lua code is processed by that interpreter.
You can think of Lua as being two parts: 1. The Lua interpreter. This is the part that lets you write for loops, if-then-else statements, assign values to variables, write your own functions, create tables of data etc. and 2. The C to Lua bridge. This provides your native side with a set of functions that lets you push values from your C, Java, ObjC code to the Lua side and fetch those values from Lua so they are available to the native functions. This bridge also lets your native side code generate events that can be caught and processed on the Lua side.
Lets take a simple example. Lua knows nothing about OpenGL and Texture memory, so a function like display.newRect() was written in C++, talks to a C based OpenGL library and creates a basic rectangular texture. When you write:
local myRect = display.newRect( 100, 100, 25, 50 )
The values for x, y, width and height are pushed on to the Lua stack and it calls the C++ function for creating a new rectangle (something one of our engineers wrote in C++). That C++ function will pop the four values off of the Lua stack, call the OpenGL function to create the texture and put the rectangle on the screen and then it pushes the address to the display object back to Lua and it gets stored in your myRect variable. Obviously, there is more going on than that to create a display object (setting up remove methods, finalize methods, fill color methods, etc.)
So nothing is being converted, just being run and calling functions. Objective C is just C with Apple’s library of functions and some additional Object-Oriented syntax going on (It’s a hybrid of C and Smalltalk.) On the Android side, Lua knows how to bridge with Java in addition to C/C++. So display.newRect() is still done with C++ for Android, but calling native.newTextField() would be calling a Java function through the Lua bridge.
Hope this helps.
Rob
Thanks Rob, that’s just incredible, it sounds like a very intricate but efficient design. I appreciate your explanation, it fills in alot of unknowns about how Corona SDK works.
Greg