top | item 41618055

(no title)

psanchez | 1 year ago

I was under de impression java gluing was required to create Android APKs. Really nice to see this project. 0 java files. Bravo.

Also worth looking at the rawandroid project like others noted: https://github.com/cnlohr/rawdrawandroid/tree/master

discuss

order

klibertp|1 year ago

The reason you have Java glue instead of C glue in most cases is that Java's is easier to write. Whatever you do, you need a Activity instance to run, and while you can create one from C, it requires a lot of boilerplate that is mostly taken care of by inheritance in Java. Here's how it's done in plain C: https://github.com/VadimBoev/FlappyBird/blob/master/FlappyBi... https://github.com/VadimBoev/FlappyBird/blob/master/FlappyBi...

pjmlp|1 year ago

Also even the "pure" C one depends on Java, because Activities exist only on the Java side of Android.

In practice to be usable on a standard Android system, native code must always be compiled to a shared object, with JNI entry points to be called from Java userspace.

The only option is to write such native methods ourselves, or use one of the two predefined Activities for NDK that already expect specific functions to be present on the shared library.

Additionally, the zero Java part only works, if what NDK exposes as stable API is enough, and from Google's point of view, that is only for games, or faster compute, everything else requires JNI fun.

As tip, it is easier to deal with Android IPC for Java <-> NDK communication, than going through JNI boilerplate.

mouse_|1 year ago

Couldn't one simply make the boilerplate once, as a library, that takes the pertinent bits as arguments? In which case if your app is C anyways it would make sense to just keep it simple with that.