The Client and Server part do not work properly
Hi Lakindu Boteju, I am new to ndk-binder. I try to use your original repository but it blocked at "Waiting to talk to IMyService...". Then I added MainActivity to the Server side( for example, NdkBinderService), and it works. In addition, If I kill the Server app (NdkBinderService), the Client (JavaBinderClient) will be blocked at "Waiting to talk to IMyService..." as before. I think your original repository should work without running App because you originally do not have MainActivity for Server sides. Please correct me if there is any misunderstanding.
Android 11 need declaring package visibility
https://developer.android.com/training/package-visibility/declaring
@ducta99, Sorry for the long delay in replying.
NdkBinderService APK only contains the Android Service implemented in C++ (no need to have an Activity in this APK). JavaBinderClient APK contains the Android Activity which binds the Android Service and calls service APIs.
- First, build and install the NdkBinderService APK.
$ ./gradlew NdkBinderService:assembleDebug
$ adb install -f NdkBinderService/build/outputs/apk/debug/NdkBinderService-debug.apk
Because NdkBinderService APK doesn't contain any main Activity, nothing will appear in the app launcher for NdkBinderService.
- Then, build and install the JavaBinderClient APK.
$ ./gradlew JavaBinderClient:assembleDebug
$ adb install -f JavaBinderClient/build/outputs/apk/debug/JavaBinderClient-debug.apk
JavaBinderClient APK have a main Activity that will appear in the app launcher.
- Finally, run the JavaBinderClient Activity from the app launcher. When you run the JavaBinderClient Activity, it will try to bind the NdkBinderService. NdkBinderService should automatically start when JavaBinderClient Activity tries to bind the service.
When I follow above 3 steps, JavaBinderClient Activity works for me everytime and displays expected output message. I am on Android 10.
@ducta99, You are correct. It doesn't work on Android 11. @xfan1024's suggestion can be the fix for this issue. I'll check from my side. Thanks @xfan1024 for the suggestion.
@xfan1024 @ducta99, Is this the fix we need? https://github.com/krnf78/AndroidNdkBinderExamples/commit/337361d04588de8c73b3a4c79720cc6490e07f08