Where should I put my compiled enterprise plugin .so files in order to get them into a Corona deployment build for Android devices?
Up until now I have only built dylib plugin files for the simulator and put them into “./Library/Application Support/Corona/Simulator/Plugins/” and the simulator finds them happily. In order to build the dylib files I skipped the Xcode build stuff and wrote a 20 row Makefile which generate the dylib file.
I would prefer to build the corresponding .so plugin files (for the Android device) using my own short Makefile as well instead of using Android Studio and gradle build inferno.
So the question is: Where should I put compiled plugin .so files so that the Corona build support adds them into the Android device build?
Kind regards
/Joakim
This is how I build own of my plugins for the simulator:
spock:sodium jocke$ ls -l total 8 drwxr-xr-x 22 jocke staff 748 22 Nov 20:44 Corona -rw-r--r-- 1 jocke staff 2307 18 Nov 20:22 Readme.markdown drwxr-xr-x 12 jocke staff 408 18 Nov 20:22 android drwxr-xr-x 13 jocke staff 442 18 Nov 20:22 ios drwxr-xr-x 5 jocke staff 170 14 Jan 09:51 mac drwxr-xr-x 3 jocke staff 102 22 Nov 11:43 shared drwxr-xr-x 8 jocke staff 272 18 Nov 20:22 tvos drwxr-xr-x 4 jocke staff 136 18 Nov 20:22 win32 spock:sodium jocke$ cd mac/ spock:mac jocke$ ls -l total 40 lrwxr-xr-x 1 jocke staff 30 18 Nov 20:22 CoronaEnterprise -\> /Applications/CoronaEnterprise -rw-r--r-- 1 jocke staff 521 1 Dec 10:45 Makefile -rwxr-xr-x 1 jocke staff 9468 14 Jan 09:51 plugin\_sodium.dylib spock:mac jocke$ make gcc -I../../../../vendor/include -I./CoronaEnterprise/Corona/shared/include/Corona -I./CoronaEnterprise/Corona/shared/include/lua -pedantic -L../../../../vendor/lib -undefined dynamic\_lookup -dynamiclib -lsodium -o plugin\_sodium.dylib ../shared/sodium.c spock:mac jocke$ ls -l plugin\_sodium.dylib -rwxr-xr-x 1 jocke staff 9468 14 Jan 20:12 plugin\_sodium.dylib spock:mac jocke$ cat Makefile INSTALLDIR="/Users/jocke/Library/Application Support/Corona/Simulator/Plugins" CFLAGS=-I../../../../vendor/include -I./CoronaEnterprise/Corona/shared/include/Corona -I./CoronaEnterprise/Corona/shared/include/lua -pedantic LFLAGS=-L../../../../vendor/lib -undefined dynamic\_lookup -dynamiclib LIBS=-lsodium LIBFILE=plugin\_sodium.dylib all: gcc $(CFLAGS) $(LFLAGS) $(LIBS) -o $(LIBFILE) ../shared/sodium.c install: install $(LIBFILE) $(INSTALLDIR) uninstall: rm -f $(INSTALLDIR)/$(LIBFILE) clean: @rm -f $(LIBFILE)
In my idealised world I thought it would be enough to manage my own AndroidManifest.xml file to specify which permissions I need for my app. Then to compile my plugins to statically linked .so files into a certain location in order for Corona to find them during its Android APK build phase.
It seems that even though I opted for Corona (Enterprise) I still have to find my way through the Android Java API and its SDK, Android Studio settings, gradle scripts and more. I have a hard time realising what to do and what *not* to do when reading the documentation I referred to above.
I can delve into all the Android Java API/SDK stuff including the workings of Android Studio and gradle scripts and more but I would prefer to be shielded from that as much as (reasonably) possible.
Corona does not cover the native, as they expect you to cover it yourself. I found it much easier to learn through their examples (in the downloaded Sample folder) and also their online codes here : https://bitbucket.org/coronalabs
I tried to use the same naming convention in my app:
$ ls -l android/ total 256 -rwxr-xr-x 1 jocke staff 124812 14 Jan 22:57 libplugin.sodium.so -rw-r--r-- 1 jocke staff 167 16 Jan 09:27 metadata.lua
I built the APK and tried but the device can still not find the plugin. I then tried to put the .so file under android/armeabi-v7a instead. Then under libs. Nothing worked on the device.
Any hints?
I must be reading the wrong documentation. Or too many of them.
I just plan to use my plugin in my app. I will be using the luaproc store plugin as well but both of them (their .so files and metadata.lua files) have to be put in the correct position in order for the APK to work in the end.
Aha. I thought you were trying to submit a plugin to the Corona Marketplace. Disregard everything I’ve said so far as it only applies to Marketplace plugin submissions
To include ‘.so’ files into your Android Studio project you’ll need to do a few things:
Copy all the extra ‘.so’ files you plan to use into the directory app/libs/armeabi-v7a
(forget about the metadata.lua files. They’re not needed in Android Studio)
$ cat Corona/main.lua local Sodium = require "plugin.sodium"; assert(false, tostring(Sodium))
I then built an Android APK but the plugin .so file can still not be found (see attachment). Do you have a pointer into documentation which talks about how to do this. I must have missed it.
I put my .so files in app/libs/armeabi-v7a/ and it all works on Android 7.x devices but to my surprise not on Android 6.x devices.
The short story is that I have my plugin libplugin.sodium.so which in turn depend on the third party library libsodium.so. Both of them sits in the armeabi-v7a/ folder and the apps work on my Android 7.x device (Google Nexus 5x).
On my Android 6.x device it fails with ‘dlopen failed: library “libsodium.so” not found’. See runtime-error.jpg attachment.
The surprising thing is that it works on 7.x devices and not on 6.x devices (not vice versa).
I assume you already have added a Gradle task to your build.gradle (Module app) to copy them over to the $jniLibsDir as described above?
It’s important that your new custom task should have: dependsOn “copyCoronaNativeLibs”, and that the dependsOn in task certifyBuild is dependsOn “copyMyNativeLibs”.
Yes, i have added gradle rules so that all the .so files in my last reply are copied. The problem seems to be that the libplugin.sodium.so is loaded ok and in turn its wants to use the libsodium.so library (which resides in the same folder as itself). This fails on Android 6.x devices. The same APK file works on Android 7.x devices though. That is the strange thing.
I’m a bit at a loss as all ‘so’ files are included in your APK.
Since it runs on your Android 7 device I’m grasping at straws here. It may be your Android 7 device supports 64 bit while your Android 6 device doesn’t. Where did you get the libsodium.so file, and are you certain the one you have is not 64-bit? It needs to be 32-bit.