Archived
Configure Ice in android studio
**Hello,
1- I am trying to setup an android project using ice. Unfortunately I can not get it work. I get this error:
**
A problem was found with the configuration of task ':app:compileSlice' (type 'SliceTask').
- In plugin 'com.zeroc.gradle.ice-builder.slice' type 'com.zeroc.gradle.icebuilder.slice.SliceTask' property 'timestamps' is missing an input or output annotation.
Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.Exception is:
org.gradle.internal.execution.WorkValidationException: A problem was found with the configuration of task ':app:compileSlice' (type 'SliceTask').- In plugin 'com.zeroc.gradle.ice-builder.slice' type 'com.zeroc.gradle.icebuilder.slice.SliceTask' property 'timestamps' is missing an input or output annotation.
Reason: A property without annotation isn't considered during up-to-date checking.
Possible solutions:
- Add an input or output annotation.
- Mark it as @Internal.
**2- In my build gradle file i add:
**
plugins { id 'com.android.application' id "com.zeroc.gradle.ice-builder.slice" version "1.4.7" } dependencies { implementation 'com.zeroc:ice:3.7.4' }
**
3- Here is my client implementation code
**
try(com.zeroc.Ice.Communicator communicator = com.zeroc.Ice.Util.initialize()) { // #base = ic.stringToProxy("SimplePrinter:tcp -h 192.168.154.161 -p 10000") com.zeroc.Ice.ObjectPrx base = communicator.stringToProxy("SimplePrinter:default -p 10000"); // com.zeroc.Ice.ObjectPrx base = communicator.stringToProxy("SimplePrinter:tcp -h 192.168.65.161 -p 10000"); com.example.asr.Demo.PrinterPrx printer = com.example.asr.Demo.PrinterPrx.checkedCast(base); if(printer == null) { throw new Error("Invalid proxy"); } printer.printString("Hello World!"); }
Comments
-
This is for my middleware project at Avignon University and I am running out of time.
Thank your for your help.0 -
You should update the builder version from 1.4.7 to 1.5.0
https://plugins.gradle.org/plugin/com.zeroc.gradle.ice-builder.slice
1 -
Thanks for your help, there is no more errors when compiling but I am trying to print a simple text message using a real android device and it is not working. Here is my implementation:
try(com.zeroc.Ice.Communicator communicator = com.zeroc.Ice.Util.initialize()) { // #base = ic.stringToProxy("SimplePrinter:tcp -h 192.168.154.161 -p 10000") //com.zeroc.Ice.ObjectPrx base = communicator.stringToProxy("SimplePrinter:default -p 10000"); com.zeroc.Ice.ObjectPrx base = communicator.stringToProxy("SimplePrinter:tcp -h 10.120.25.162 -p 10000"); Log.d("Ice","This code is executed"); com.example.asr.Demo.PrinterPrx printer = com.example.asr.Demo.PrinterPrx.checkedCast(base); Log.d("Ice","This line is not executed"); if(printer == null) { Log.d("Adapter","2"); throw new Error("Invalid proxy"); } Log.d("Ice","This part is not excuted"); printer.printString("Hello World!"); Log.d("Adapter","Print String works"); }catch(Exception e){ Log.d("Exeption","ice failed"); System.out.println(e); }
Could you please help me?
Thank you!!
0 -
The
checkedCast
operation does a remote produce call, if the device cannot contact the remote endpoint it could take some time to get a failure, You should add an invocation timeout to ensure this can report a failure in a timely manner, enabling network and protocol tracing is also helpful to debug issues like this:InitializationData initData = new InitializationData(); initData.properties = Util.createProperties(); initData.properties.setProperty("Ice.Trace.Network", "3"); initData.properties.setProperty("Ice.Trace.Protocol", "1"); try(com.zeroc.Ice.Communicator communicator = com.zeroc.Ice.Util.initialize(initData)) { ... com.zeroc.Ice.ObjectPrx base = communicator.stringToProxy("SimplePrinter:tcp -h 10.120.25.162 -p 10000"); base.ice_invocationTimeout(2000); // 2 seconds ... }
0 -
When debugging I find this: System.out: com.zeroc.Ice.SocketException
0 -
I/System.out: java.net.SocketException: Operation not permitted
0 -
Seems like your application manifest is missing the permissions to access the network, see https://github.com/zeroc-ice/ice-demos/blob/f362b7f0115134659e092a35b1eec7d503b234a9/java/android/hello/src/main/AndroidManifest.xml#L7-L11
Those are better documented in Android documentation.
1 -
Hello, it works now, but there is an other issue. The app closed unexpectedly when i launch it on my phone. I do not have any idea about this issue.
0 -
Here is my server configuration.
try: ic = Ice.initialize(sys.argv) adapter = ic.createObjectAdapterWithEndpoints( "SimplePrinterAdapter", "tcp -p 10000") object = PrinterI() adapter.add(object, ic.stringToIdentity("SimplePrinter")) adapter.activate() ic.waitForShutdown() except: traceback.print_exc() status = 1 if ic: # Clean up try: ic.destroy() except: traceback.print_exc() status = 1
Android client:
try(com.zeroc.Ice.Communicator communicator = com.zeroc.Ice.Util.initialize()) { // #base = ic.stringToProxy("SimplePrinter:tcp -h 192.168.154.161 -p 10000") //com.zeroc.Ice.ObjectPrx base = communicator.stringToProxy("SimplePrinter:default -p 10000"); Log.d("Ice","This code is executed"); com.zeroc.Ice.ObjectPrx base = communicator.stringToProxy("SimplePrinter:tcp -h 192.168.248.161 -p 10000"); Log.d("Ice","This code is executed"); com.example.asr.Demo.PrinterPrx printer = com.example.asr.Demo.PrinterPrx.checkedCast(base); Log.d("Ice","This line is not executed"); if(printer == null) { Log.d("Adapter","2"); throw new Error("Invalid proxy"); } Log.d("Ice","This part is not executed"); printer.printString("Hello World!"); Log.d("Adapter","Print String works"); }catch(Exception e){ Log.d("Exception","ice failed"); System.out.println(e.getMessage()); }
At the end the printer is null when i using a real android device. By using an other client from an other computer it works fine.But it does not work when using my android real device.
0 -
does it work with android simulator? does the checked cast return a null proxy or throws an exception?
0 -
It returns a null proxy.
0 -
It does not work with emulator.
0 -
If
checkedCast
returns null it means the target object doesn't implement the given interface, this could happen if there is a mismatch between the client and server definitions.But in your example it reads
Log.d("Ice","This line is not executed");
If this is not executed then
checkedCast
must be throwing an exception.0 -
Yes this line is executed. But printer always returns null.
0