Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some classes need to be extended in some cases, however currently it is not possible #75

Open
masesdevelopers opened this issue Aug 3, 2024 · 8 comments · Fixed by #82
Assignees
Labels
enhancement New feature or request java .NET

Comments

@masesdevelopers
Copy link
Contributor

masesdevelopers commented Aug 3, 2024

The following code

public void OnCreate(Android.Os.Bundle arg0, Android.Os.PersistableBundle arg1)
must be like a callback and cannot be managed like an invocable method. A classic snippet is like:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState, PersistableBundle pers) {
        super.onCreate(savedInstanceState, pers);
        setContentView(R.layout.activity_main);
    }
}

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

public void SetContentView(int arg0)
that shall be an invocable method.

@masesdevelopers masesdevelopers added enhancement New feature or request java .NET labels Aug 3, 2024
@masesdevelopers masesdevelopers self-assigned this Aug 3, 2024
@masesdevelopers masesdevelopers changed the title Some classes expected to be exetended in some cases, however currently it is not possible Some classes need to be exetended in some cases, however currently it is not possible Aug 3, 2024
@masesdevelopers
Copy link
Contributor Author

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

public void SetContentView(int arg0)

that shall be an invocable method.

There are two possible alternatives to create some classes that needs the behavior requested:

  • manually develops the behavior using some new classes defined in JVM side
  • request an enhancement to JNetReflector

@masesdevelopers masesdevelopers linked a pull request Sep 20, 2024 that will close this issue
9 tasks
@masesdevelopers masesdevelopers changed the title Some classes need to be exetended in some cases, however currently it is not possible Some classes need to be extended in some cases, however currently it is not possible Sep 20, 2024
@masesdevelopers
Copy link
Contributor Author

To use latest version of JNetReflector (see #82) a new class from JNet shall be introduced, so it is important to close #76

@masesdevelopers
Copy link
Contributor Author

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

@masesdevelopers
Copy link
Contributor Author

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 #75 (comment)), the other one were managed like standard classes.

@masesdevelopers
Copy link
Contributor Author

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:
image
image

@masesdevelopers
Copy link
Contributor Author

masesdevelopers commented Sep 25, 2024

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.*

See https://learn.microsoft.com/it-it/dotnet/standard/base-types/regular-expression-language-quick-reference

masesdevelopers added a commit to masesdevelopers/netdroid that referenced this issue Sep 25, 2024
masesdevelopers added a commit to masesdevelopers/netdroid that referenced this issue Sep 25, 2024
@masesdevelopers
Copy link
Contributor Author

masesdevelopers commented Sep 27, 2024

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


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*.

@masesdevelopers
Copy link
Contributor Author

masesdevelopers commented Sep 27, 2024

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

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*.

Not applicable due to #104 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request java .NET
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant