I'm struggling with using properties in AllJoyn. I'm new to AllJoyn but not to programming. I have a provider written C++ and I add my properties using
status = m_Description->AddProperty("ServerName", "s", 1)
After that call status equals ER_OK.
I define my Java Property in the interface as the following:
@BusProperty(annotation = BusProperty.ANNOTATE_EMIT_CHANGED_SIGNAL)
String getServerName() throws BusException;
However, when I try to use the property on in Java (Android using Android Studio) by making the call as:
String str = proxyInterface.getServerName();
I keep getting the following exception:
04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: org.alljoyn.bus.AnnotationBusException: field public static transient volatile com.android.tools.fd.runtime.IncrementalChange com.wolfecomputerservices.cumulus.ui.Android.Communication.AllJoyn.Objects.ServerData.$change of class com.wolfecomputerservices.cumulus.ui.Android.Communication.AllJoyn.Objects.ServerData does not annotate position 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.Signature.structTypes(Signature.java:71) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.Signature.classTypeSig(Signature.java:170) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.Signature.typeSig(Signature.java:117) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.InterfaceDescription.getOutSig(InterfaceDescription.java:511) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.InterfaceDescription.addMembers(InterfaceDescription.java:386) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.InterfaceDescription.create(InterfaceDescription.java:199) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.ProxyBusObject.addInterface(ProxyBusObject.java:115) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.ProxyBusObject.getProperty(Native Method) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.ProxyBusObject.access$400(ProxyBusObject.java:35) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at org.alljoyn.bus.ProxyBusObject$Handler.invoke(ProxyBusObject.java:274) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at java.lang.reflect.Proxy.invoke(Proxy.java:397) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at $Proxy4.getServerRunning(Unknown Source) 04-07 10:11:45.592 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at com.wolfecomputerservices.cumulus.ui.Android.Communication.AllJoyn.Interfaces.ICumulusImpl.IsRunning(ICumulusImpl.java:24) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at com.wolfecomputerservices.cumulus.ui.Android.Communication.AllJoyn.Handlers.BusHandler.processMessage(BusHandler.java:276) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at com.wolfecomputerservices.cumulus.ui.Android.Abstracts.PauseHandler.handleMessage(PauseHandler.java:75) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at android.os.Handler.dispatchMessage(Handler.java:111) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at android.os.Looper.loop(Looper.java:194) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5567) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at java.lang.reflect.Method.invoke(Native Method) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at java.lang.reflect.Method.invoke(Method.java:372) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955) 04-07 10:11:45.593 26005-26005/com.wolfecomputerservices.cumulus W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
Note: I do have a method that has a return value of ServerData. However, that is not what I'm calling when this error occurs. I sucessfully make that call long before trying to call the method. It is the method call that causes this exception. However, I do have ServerData annotated with @Position(x) for each field number 0-4.
What am i doing wrong?
Update:
ServerData from C++ Provider
class ServerData {
public:
const char* Id;
const char* Name;
const char* Version;
const char* MachineName;
const char* BaseUrl;
};
From Java Consumer:
public class ServerData {
@Position(0)
@Signature("s")
public String Id;
@Position(1)
@Signature("s")
public String Name;
@Position(2)
@Signature("s")
public String Version;
@Position(3)
@Signature("s")
public String MachineName;
@Position(4)
@Signature("s")
public String BaseURL;
}
UPDATE: Unfortunately, that doesn't seem possible for me to switch version of gradle. I'm currently on 2.3.1; switching to 2.1.3 causes the following error during build (I've tried all the suggestions listed):
Unfortunately, that doesn't seem possible for me to switch version of gradle. I'm currently on 2.3.1; switching to 2.1.3 causes the following error during build: Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:
Make sure that the ServerData fields in question are public and that there is no typo in any of the @Position(n) annotations that you have specified immediately before each public field.
UPDATE:
I have seen this Annotation error message when building in Android Studio with gradle 2.2.3. However, when I went back to using gradle 2.1.3 the annotation error went away.
Check your top level build.gradle file. Update its classpath dependency to be...
dependencies { classpath 'com.android.tools.build:gradle:2.1.3' }
UPDATE 2:
Another workaround, if you need to build in Android Studio with gradle > 2.1.3, is to disable Android Studio's "instant run" feature. The instant run feature is automatically adding two public static fields to classes (i.e. it is adding the $change field and the serialVersionUID field).
The AllJoyn java-binding's processing of the Position annotations (which is done via reflection) does not currently account for these two fields being added by the compiler. This will be handled better by AllJoyn in its upcoming 16.10a maintenance release).
To disable "instant run", do the following within Android Studio...
Open the Settings or Preferences dialog.
Navigate to Build, Execution, Deployment > Instant Run.
Uncheck the "Enable Instant Run to hot swap/resource changes on deploy" checkbox.