AndroidNdkBinderExamples icon indicating copy to clipboard operation
AndroidNdkBinderExamples copied to clipboard

The Client and Server part do not work properly

Open ducta99 opened this issue 4 years ago • 4 comments

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.

ducta99 avatar Feb 26 '22 02:02 ducta99

Android 11 need declaring package visibility

https://developer.android.com/training/package-visibility/declaring

xfan1024 avatar Apr 19 '22 06:04 xfan1024

@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.

  1. 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.

  1. 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.

  1. 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.

lakinduboteju avatar May 18 '22 16:05 lakinduboteju

@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.

lakinduboteju avatar May 18 '22 16:05 lakinduboteju

@xfan1024 @ducta99, Is this the fix we need? https://github.com/krnf78/AndroidNdkBinderExamples/commit/337361d04588de8c73b3a4c79720cc6490e07f08

lakinduboteju avatar Dec 11 '24 09:12 lakinduboteju