Closed ylz-at closed 3 years ago
Currently, there is no way to create a purely native (C++) service with Android NDK.
Service implementation must be written in Java, but with new NdkBinder
API you can write purely C++ binder implementations, as I have done in this repository.
The example you have pointed out is not an Android application service. It is a purely native (C++) system service.
You can bring up this kind of a system service, only if you have the luxury of creating your own AOSP build (Android OS build).
Or at least you must have root access to your Android device.
In general, you cannot deploy a purely native (C++) system service using an APK. As it would compiled into an executable file, that should be run at the Android bootup process using an entry in the AOSP's init.rc
file.
Moreover, defaultServiceManager()
function is not a part of NDK. If you want to work with the default service manager, you must use Android platform libraries instead of NDK.
Is it possible to have a Java service and a pure C++ client without having a Java activity? I want to put the C++ client in an shared library (.so) build with NDK and have no activity at hand.
I found that you are using MyService.java to create binder. Some other examples are registering service to defaultServiceManager(). https://github.com/qianjigui/android_system_service_example/blob/master/server/main.cpp