Hi @GordonBGood!

As a quick side note regarding Dali, I'm actually still slowly chipping in at 
progressing with the project when I can, with my current goal being to try and 
write a very basic game-like graphical demo with it. My ultimate goal is also 
to be able to write GUI apps, but I decided a demo like this would be a nice 
intermediate milestone, while also giving me a bit more fun (which is the 
crucial currency in purely hobby projects), as well as being already useful to 
some people. However, even with that, I can't give any concrete timeline. With 
every step forward a new complication or bug tends to show up, that I must then 
find the reason of and resolve. And until I'm there, there's just nothing 
really to show. I will try to remember to ask you if you're still interested in 
writing some polished tutorial when I reach a point when I'll be starting to 
dig at it myself. That's an important and task indeed in my opinion too, and I 
found it also tends to require a lot of energy, so the more at it the merrier, 
I hope.

Now, having said that, I totally understand you being OK with using Android 
Studio. That's the reasonable choice. So, if you're interested in writing a 
tutorial for this approach, personally I would probably recommend to go with a 
path more or less like this:

  1. Try and start with bootstrapping a simplest possible Android NDK tutorial, 
and then making sure you can successfully run the resulting app on your Android 
device or simulator.
  2. Then, try and generate the same C code as in the tutorial, but from Nim. I 
suggest importing the `jni_wrapper.nim` module from yglukhov's jnim, it 
contains the same contents as "jni.h" in C, which is very simple and very 
useful for starters. Now, crucially, you need to write function with a name 
conforming to JNI protocol, so for function declared `public native int 
world();` in file com/gordonbgood/HelloActivity.java, you would need something 
like a `proc Java_com_gordonbgood_HelloActivity_world*(jenv: JNIEnvPtr; jthis: 
jobject): jint {.cdecl, exportc, dynlib.} = return 42` in your `hello_jni.nim`. 
Now, try to `nim c` this file with the Android NDK cross-compiler, see e.g. [my 
nim.cfg from dali's hellomello 
demo](https://github.com/akavel/hellomello/blob/948e3ba205ca637eaca6438c86be25ed65dd10b4/nim.cfg).
 Again, if you succeed, verify that the .apk you build with Android Studio 
successfully runs on your Android device. If not... what can I say, try running 
`adb logcat`, then Ctrl-C it immediately after the crash, and backtrack to try 
finding some helpful-looking stacktraces that will hopefully hint you in right 
direction. Or maybe Android Studio has some helper tools for collecting and 
browsing logcat logs?
  3. If you managed to complete above step, you can try bringing in more of 
jnim. As yglukhov mentioned above, it's basically a hobby project too, so be 
prepared that you may stumble upon quite a lot of missing pieces, and maybe 
even bugs occasionally. The missing pieces you may be able to try and 
contribute back to the project, while the bugs you may either try to fix 
yourself, or report to yglukhov with as simple and helpful hints as possible, 
to make it easier for him to find time and energy to try resolving. Still, 
github.com/yglukhov/jnim together with github.com/yglukhov/android will save 
you from writing _a 
[looooot](https://forum.nim-lang.org/postActivity.xml#looooot) of boilerplate. 
They're an absolute gem if you're trying to write Android NDK code in Nim.
  4. Optionally, you may then try to take a look at `jexport` macro in jnim; 
however, please note that this one is even more experimental than jnim itself. 
I'm actually trying to use it in Dali, in collaboration and with invaluable 
help and support from @yglukhov, so as to not duplicate effort/reinvent the 
wheel. However we're still regularly finding some areas in need of improvement 
there and slowly trying to bring it closer to general usability, with me 
working basically as a glorified crazy guinea pig, and @yglukhov patiently 
trying to help me in the especially narrow places on my way to the end of the 
labirynth (or at least something like that...)
  5. ???
  6. Profit!



But that's just my $0.02; maybe jnim gives some easier way, I'm not really sure 
as I'm personally not at all interested in using JDK/Android Studio, so didn't 
explore if there are any shortcuts possible on this path. But all in all, I 
believe the steps I outlined above are what you need to do some way or another 
to reach your goal, if I understood it correctly. I think they also serve as 
good "control points" along the way, to make sure you have a solid foundation 
before jumping one step higher, and thus less things to debug when something's 
not working right (and it will be...)

Good luck!

Reply via email to