lakinduboteju / AndroidNdkBinderExamples

Android NDK (C++) Binder examples : Explains how to implement Android services and clients in C++
108 stars 23 forks source link

The Client and Server part do not work properly #5

Open ducta99 opened 2 years ago

ducta99 commented 2 years ago

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.

xfan1024 commented 2 years ago

Android 11 need declaring package visibility

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

lakinduboteju commented 2 years ago

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

  2. 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 commented 2 years ago

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