ndk icon indicating copy to clipboard operation
ndk copied to clipboard

vendor NativeActivity

Open dvc94ch opened this issue 4 years ago • 4 comments

I suspect that this would be a good first step for doing things like #128 and decoupling cargo-apk from any NativeActivity limitations.

cc @canndrew

dvc94ch avatar May 30 '21 10:05 dvc94ch

I don't think this needs to be done. You can create a subclass of NativeActivity in Java and then add any extra Java hooks you need from there (including writing a NativeService subclass and calling native/rust-implemented methods from it). You can then call RegisterNatives from Rust to register native methods with Dalvik, and use JNI to call any Java methods you want (most likely the methods you call from JNI will be helper methods you add to your NativeActivity subclass, and then you'll call on into the Android class library from there).

The alternative to doing this would be to make a plain JNI library, define a new method for forwarding input events and setting up a GL context, and write new code to cover a lot of what the NDK already does. There are definitely places in Android where you might want to do that (like anywhere you can't have an Activity), but for most use cases the current Rust NDK bindings are probably easiest and involve making the least new code ;).

iamralpht avatar Jun 15 '21 00:06 iamralpht

You can create a subclass of NativeActivity in Java and then add any extra Java hooks you need from there (including writing a NativeService subclass and calling native/rust-implemented methods from it).

I guess that makes sense. But cargo-apk would still need this subclass and support for compiling and including this subclass in the final apk right?

dvc94ch avatar Jun 15 '21 08:06 dvc94ch

Yeah, cargo-apk doesn't know how to build Java bits, so I've been copying the shared objects it builds into a traditional Android project built with gradle (so I discard the APK built with cargo-apk, and I'd disable building the APK and manifest if I could). This way I can also use the Android tools to edit the Java code.

iamralpht avatar Jun 15 '21 19:06 iamralpht

Yes, so the goal would be that you don't have to do that. That's what I'm suggesting in this issue. You can use cargo apk check to create just the so's.

dvc94ch avatar Jun 15 '21 20:06 dvc94ch

can be closed as out of scope

dvc94ch avatar Nov 17 '22 16:11 dvc94ch