Where to put android library files
-
- Posts: 6
- Joined: Tue Apr 17, 2018 3:31 pm
Where to put android library files
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
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
-
- Livecode Staff Member
- Posts: 192
- Joined: Thu Apr 18, 2013 2:48 pm
Re: Where to put android library files
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:
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
-
- Posts: 6
- Joined: Tue Apr 17, 2018 3:31 pm
Re: Where to put android library files
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: seems being deployed into My Livecode Extensions folder correctly: 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.
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: seems being deployed into My Livecode Extensions folder correctly: 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.
-
- Livecode Staff Member
- Posts: 192
- Joined: Thu Apr 18, 2013 2:48 pm
Re: Where to put android library files
Your code and everything looks correct, with the exception of
As the sayHelloAndroid method is static, your binding string should be
Code: Select all
__safe foreign handler JNI_SayHello() returns JString binds to "java:com.example.uhfreader816ubt.HelloAndroid>sayHelloAndroid()Ljava/lang/String;"
Code: Select all
java:com.example.uhfreader816ubt.HelloAndroid>sayHelloAndroid()Ljava/lang/String;!static
-
- Posts: 6
- Joined: Tue Apr 17, 2018 3:31 pm
Re: Where to put android library files
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 ...
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 ...
-
- Posts: 641
- Joined: Tue Jul 29, 2014 12:52 am
- Location: Brazil
Re: Where to put android library files
@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
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
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question