Page 1 of 1

Where to put android library files

Posted: Tue Apr 17, 2018 3:46 pm
by patrickshing
We are trying to embed an RFID reader to our android apps, starting to dive in LCB, just finished the Hello World exercise.

Then, we put all android library files in the working folder, and add in these 3 lines in our lcb file:
use com.livecode.foreign
use com.livecode.java
use MyService.java

(MyService.java being one of the source android files provided by the RFID vendor)

When we click the Test button, LCB issues an error: Unable to find imported module 'MyService.java'

So, where should we put the library files?

Please give a direction to proceed.


Thanks group :)

Re: Where to put android library files

Posted: Tue Apr 17, 2018 11:11 pm
by livecodeali
At the moment, LCB extensions can only interface with compiled java classes through foreign handler bindings.
So, you will need to compile all the source files into a .jar file (or download a .jar file provided by the vendor) and put it in a folder code/jvm-android next to the lcb file. Then, you will be able to call public methods in classes in the compiled jar.

For example, say the MyService class has a constructor and a public method void doSomething(), and suppose the package name is com.vendor.RFID, then you could create an instance of the class and call doSomething using foreign handler bindings:

Code: Select all

__safe foreign handler JNI_MyServiceConstructor() returns JObject binds to "java:com.vendor.RFID.MyService>new()"
__safe foreign handler JNI_MyServiceDoSomething(in pService as JObject) returns nothing binds to "java:com.vendor.RFID.MyService>doSomething()V"

handler CreateServiceAndCallDoSomething()
    variable tService as JObject
    put JNI_MyServiceConstructor() into tService
    JNI_MyServiceDoSomething(tService)
end handler

Re: Where to put android library files

Posted: Tue Apr 24, 2018 7:28 am
by patrickshing
I'm still stuck in linking up with android library!

Using a simple java:
=================================================
package com.example.uhfreader816ubt;

public class HelloAndroid
{
public static String sayHelloAndroid()
{
return "Hello Android!";
}
}
==================================================

I've built the .jar file and put it in code/jvm-android folder alongside my lcb file:
===================================================
library com.livecode.library.uhfreader

metadata version is "1.0.0"
metadata author is "Patrick Shing"
metadata title is "UHF Reader"

use com.livecode.foreign
use com.livecode.java

__safe foreign handler JNI_SayHello() returns JString binds to "java:com.example.uhfreader816ubt.HelloAndroid>sayHelloAndroid()Ljava/lang/String;"

public handler sayHelloAndroid() returns String
return StringFromJString(JNI_SayHello())
end handler

public handler sayHello() returns String
return "hello world"
end handler

end library
========================================================

everything seems smooth in the IDE, no errors; I select the "UHF Reader" in the standalone options and build the apk file.

the working folder structure:
working folder.png
working folder.png (29.69 KiB) Viewed 6975 times
seems being deployed into My Livecode Extensions folder correctly:
My LiveCode Extensions folder.png
My LiveCode Extensions folder.png (41.67 KiB) Viewed 6975 times
But in the apps, I can only get the straight forward "hello world", and the "Hello Android" seems never got returned (only blank, nothing returns)!

Since the codes had been reduced to an absolute minimum, I feel that I cannot get the jar file embedded in the apk! Please advise how should I move forward.

Thanks.

Re: Where to put android library files

Posted: Fri Apr 27, 2018 1:11 pm
by livecodeali
Your code and everything looks correct, with the exception of

Code: Select all

__safe foreign handler JNI_SayHello() returns JString binds to "java:com.example.uhfreader816ubt.HelloAndroid>sayHelloAndroid()Ljava/lang/String;"
As the sayHelloAndroid method is static, your binding string should be

Code: Select all

java:com.example.uhfreader816ubt.HelloAndroid>sayHelloAndroid()Ljava/lang/String;!static

Re: Where to put android library files

Posted: Mon Apr 30, 2018 3:24 am
by patrickshing
Excellent! It works now!

Thank you very much for leading me into the door of android library with LC Builder!

Will have some crazy busy days into my RFID project ...

Re: Where to put android library files

Posted: Wed Oct 03, 2018 10:23 pm
by simon.schvartzman
@patrickshing, hi are you by any chance using the Chainway RFID reader?

https://www.chainway.net/Products/Info/42

I should start a project with that environment LC + Chainway RFID reader an may be you can help me...

Thanks in advance