Open masesdevelopers opened 3 months ago
From the point of view of .NET code in Netdroid, the 'OnCreate' shall be managed like an event of a listener. In this way the .NET code can react and execute the needed code like
https://github.com/masesgroup/netdroid/blob/84d980756a94c0350b6bbb787d530be6d98d27bf/src/net/Netdroid/Generated/Android/App/Activity.cs#L1957 that shall be an invocable method.
There are two possible alternatives to create some classes that needs the behavior requested:
To use latest version of JNetReflector (see #82) a new class from JNet shall be introduced, so it is important to close #76
Using latest version of JNetReflector it is not possible to obtain the expected result.
With the first attempt using android.app.Activity
it is possible to highlight that the following configuration snippet
"ClassesWithCallbacks": [
{
"ClassName": "android.app.Activity",
"Patterns": [
"on*"
]
}
],
fails the generation with:
Patterns
does not work and all methods are created as callbacks then compiling Java side most of the errors reports overridden method is final
Extending the list of classes under ClassesWithCallbacks
section another issue were identified. The updated configuration is:
"ClassesWithCallbacks": [
{
"ClassName": "android.app.Activity",
"Patterns": [
"on*"
]
},
{
"ClassName": "android.app.NativeActivity",
"Patterns": [
"on*"
]
},
{
"ClassName": "android.app.ListActivity",
"Patterns": [
"on*"
]
},
{
"ClassName": "android.app.ExpandableListActivity",
"Patterns": [
"on*"
]
},
{
"ClassName": "android.app.AliasActivity",
"Patterns": [
"on*"
]
},
{
"ClassName": "android.app.ActivityGroup",
"Patterns": [
"on*"
]
}
],
however only android.app.Activity
, android.app.NativeActivity
and android.app.ExpandableListActivity
were recognized (and they have the same problems reported in https://github.com/masesgroup/netdroid/issues/75#issuecomment-2372629131), the other one were managed like standard classes.
Outside from the topic of this issue, the generation of the methods is not stable. Run by run, JNetReflector writes some files using execution stub with different behaviors:
Using latest version of JNetReflector it is not possible to obtain the expected result. With the first attempt using
android.app.Activity
it is possible to highlight that the following configuration snippet"ClassesWithCallbacks": [ { "ClassName": "android.app.Activity", "Patterns": [ "on*" ] } ],
fails the generation with:
* `Patterns` does not work and all methods are created as callbacks then compiling Java side most of the errors reports `overridden method is final` * in .NET side all methods are callbacks (implicitly from the previous), but some other information, like fields, are removed
Patterns
uses regular expressions. all methods are created as callbacks is not true because the pattern means that only methods containing, in the method name, the literal on shall be managed like callbacks. Start to replace on*
with ^on*
if the you expect to have callbacks on methods whose name starts with the literal on.
UPDATE: maybe a better regex is ^on.*
Last generation reports in the log:
Error: JVMClass: ClassNotFoundException loading java.util.SequencedMap with message: java.util.SequencedMap
Error: JVMClass: ClassNotFoundException loading java.util.SequencedSet with message: java.util.SequencedSet
Error: JVMClass: ClassNotFoundException loading java.util.jar.Pack200 with message: java.util.jar.Pack200
Error: JVMClass: ClassNotFoundException loading java.util.jar.Pack200$Unpacker with message: java.util.jar.Pack200$Unpacker
Error: JVMClass: ClassNotFoundException loading java.util.jar.Pack200$Packer with message: java.util.jar.Pack200$Packer
Error: JVMClass: ClassNotFoundException loading java.util.SequencedCollection with message: java.util.SequencedCollection
The classes java.util.SequencedMap
, java.util.SequencedSet
, java.util.SequencedCollection
available starting from API Level 35 are defined in JDK 21, so https://github.com/masesgroup/netdroid/blob/b53985d5209f6d2b99adc906453de6a1c11b8005/.github/workflows/generateclasses.yaml#L85
shall be raised up to 21.
The other classes (java.util.jar.Pack200
) are available using a JDK 11 because they were removed in release 14: https://openjdk.org/jeps/367.
We prefer to have java.util.Sequenced*
.
Last generation reports in the log:
Error: JVMClass: ClassNotFoundException loading java.util.SequencedMap with message: java.util.SequencedMap Error: JVMClass: ClassNotFoundException loading java.util.SequencedSet with message: java.util.SequencedSet Error: JVMClass: ClassNotFoundException loading java.util.jar.Pack200 with message: java.util.jar.Pack200 Error: JVMClass: ClassNotFoundException loading java.util.jar.Pack200$Unpacker with message: java.util.jar.Pack200$Unpacker Error: JVMClass: ClassNotFoundException loading java.util.jar.Pack200$Packer with message: java.util.jar.Pack200$Packer Error: JVMClass: ClassNotFoundException loading java.util.SequencedCollection with message: java.util.SequencedCollection
The classes
java.util.SequencedMap
,java.util.SequencedSet
,java.util.SequencedCollection
available starting from API Level 35 are defined in JDK 21, soshall be raised up to 21.
The other classes (
java.util.jar.Pack200
) are available using a JDK 11 because they were removed in release 14: https://openjdk.org/jeps/367.We prefer to have
java.util.Sequenced*
.
Not applicable due to https://github.com/masesgroup/netdroid/pull/104#issuecomment-2379753744
The following code https://github.com/masesgroup/netdroid/blob/84d980756a94c0350b6bbb787d530be6d98d27bf/src/net/Netdroid/Generated/Android/App/Activity.cs#L1516 must be like a callback and cannot be managed like an invocable method. A classic snippet is like:
The previous overrides
onCreate
and executes some extra code. So, from the point of view of .NET code in Netdroid, the 'OnCreate' shall be managed like an event of a listener. In this way the .NET code can react and execute the needed code like https://github.com/masesgroup/netdroid/blob/84d980756a94c0350b6bbb787d530be6d98d27bf/src/net/Netdroid/Generated/Android/App/Activity.cs#L1957 that shall be an invocable method.