dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
155 stars 43 forks source link

jnigen iterative development loop with plugin code is awkward #1660

Open stuartmorgan opened 3 weeks ago

stuartmorgan commented 3 weeks ago

The recommended workflow of building plugin source and then jnigening the resulting output doesn't work very well when iterating on hybrid development (e.g., migrating code from native to Dart). I've hit a variant of this flow quite a few times now:

  1. Try to write some Dart code using my plugin code.
  2. Realize that I can't access SomeJavaClass in Dart because it wasn't marked public (only becomes an issue when trying to call the code from Dart).
  3. Update the Java code.
  4. Try to flutter build the example app so that I can re-run jnigen now that it's public.
  5. Fail to build because of the in-progress code in step 1.

Obviously if I don't save in step 1 I wouldn't have that problem, but I save all the time, including commonly doing save-all when modifying anything, including the changes to the Java code (which I'm making in VS Code as well because they are trivial). I keeping hitting this even though in theory I know better at this point. Then I have to back out or comment our enough code from step 1. to be able to continue.

It would be nice if we could identify a specific command to regenerate just the Java code, so that I could iterate on Java+jnigen runs regardless of the state of my Dart code.

HosseinYousefi commented 3 weeks ago

Yes, I have hit the same issue before: https://github.com/dart-lang/native/issues/628

I need to make some changes to flutter_tools so that it doesn't compile the Dart code if passed a certain flag. I tried this before but wasn't successful and had to move on to other tasks.

Something hacky that is easy to do:

  1. Create a new temporary flutter project
  2. Copy the android directory to that project
  3. Convert the plugin into an app if not one already or also do 1. and 2. for the example app
  4. Run flutter build apk to cache gradle dependencies
  5. Run jnigen