Android Plugin

Hi,

I want to develop an Android plugin. To start with “native builds” which I have not done before, I am following these instructions: https://docs.coronalabs.com/native/android/index.html

It complained about the gradle version, so I updated to 3.0.0 in the main project build.gradle file:

classpath 'com.android.tools.build:gradle:3.0.0'

Then it complained about the tools, it wanted to upgrade to 26.0.0, which I allowed it to do, and changed all build.gradle files to buildToolsVersion ‘26.0.2’

Then it is complaining about something else:

Error:(36, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl\_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

In the build.gradle I changed:

output.outputFile = file(output.outputFile.getPath().replace('/app-', "/${apkName}-"))

To

output.outputFileName = file( output.outputFile.getPath().replace('/app-', "/${apkName}-") )

But now it has other errors - including errors about iphoneos (this is Android??)

Error:error: SDK "iphoneos" cannot be located Error:error: unable to find utility "copypng", not a developer tool or in PATH Error:Execution failed for task ':app:compileLua'.\> Process 'command '/Users/TestUser/Library/Application Support/Corona/Native/Corona/mac/bin/lua'' finished with non-zero exit value 255

Have I lost my way? Does anyone have a working project?

There are a few on github. I have one for smaato that I was building for Amazon when Appodeal didn’t support Amazon. It should still build and would give you ideas. It is not finished and will never be but for your purposes it should be fine:

https://github.com/agramonte/smaato-corona-plugin

Good luck. It is not an easy task to build a plugin for Android.

The following shell script is being called and attempts to copy “iphoneos”

/Corona/Native/Corona/mac/bin/CopyResources.sh

I put a TARGET_PLATFORM check around the copy and it has built.

        if [["$TARGET\_PLATFORM" != "android"]]; then              COPYPNG=$(xcrun --sdk iphoneos --find copypng)              if [! -x "$COPYPNG"]              then                 echo "ERROR: cannot locate 'copypng' in Xcode"                 exit 1              fi         fi

hmmm. I thought you were trying to build for Android. That script is in the mac bin directory. What project did you open to build?

Correct. I am building Android on my Mac.

I opened the standard example as specified in the initial link: 

/Applications/Corona/Native/Project Template/App/android

I’m not sure if I really even want to make a plugin. I have a library of C functions

specialMaths.a

I want to call these functions - do I need to make a plugin?

No. You don’t have to build a plugin. You can just call the library from the Java side, but I think I see your problem. I have never linked a static C library to a Java project (it is beyond my pay grade), so I don’t think I’ll be much help. I have done it the other way around (link a Java (jar) to a C library) but don’t think the process is the same. If I have time this weekend, I’ll give it a go. I am curious if it would work.


Ok. I just looked it up and yes it is the same process as the other way around. The only way I could find to do what you want to do is to create a JNI wrapper of that library and then call it from the Java code. In my github I have a few examples of JNI wrappers. Look for plugins made for MadeWithMarmalade for Android. Most of those are wrappers. In any case, I love JNI and if I have time this weekend I’ll attempt to create one from a random library.


You can also look at:

https://en.wikipedia.org/wiki/Java_Native_Access

I downloaded your smaato, it immediately worked, I am gonna try to customise that.

There are a few on github. I have one for smaato that I was building for Amazon when Appodeal didn’t support Amazon. It should still build and would give you ideas. It is not finished and will never be but for your purposes it should be fine:

https://github.com/agramonte/smaato-corona-plugin

Good luck. It is not an easy task to build a plugin for Android.

The following shell script is being called and attempts to copy “iphoneos”

/Corona/Native/Corona/mac/bin/CopyResources.sh

I put a TARGET_PLATFORM check around the copy and it has built.

        if [["$TARGET\_PLATFORM" != "android"]]; then              COPYPNG=$(xcrun --sdk iphoneos --find copypng)              if [! -x "$COPYPNG"]              then                 echo "ERROR: cannot locate 'copypng' in Xcode"                 exit 1              fi         fi

hmmm. I thought you were trying to build for Android. That script is in the mac bin directory. What project did you open to build?

Correct. I am building Android on my Mac.

I opened the standard example as specified in the initial link: 

/Applications/Corona/Native/Project Template/App/android

I’m not sure if I really even want to make a plugin. I have a library of C functions

specialMaths.a

I want to call these functions - do I need to make a plugin?

No. You don’t have to build a plugin. You can just call the library from the Java side, but I think I see your problem. I have never linked a static C library to a Java project (it is beyond my pay grade), so I don’t think I’ll be much help. I have done it the other way around (link a Java (jar) to a C library) but don’t think the process is the same. If I have time this weekend, I’ll give it a go. I am curious if it would work.


Ok. I just looked it up and yes it is the same process as the other way around. The only way I could find to do what you want to do is to create a JNI wrapper of that library and then call it from the Java code. In my github I have a few examples of JNI wrappers. Look for plugins made for MadeWithMarmalade for Android. Most of those are wrappers. In any case, I love JNI and if I have time this weekend I’ll attempt to create one from a random library.


You can also look at:

https://en.wikipedia.org/wiki/Java_Native_Access

I downloaded your smaato, it immediately worked, I am gonna try to customise that.