mlkit icon indicating copy to clipboard operation
mlkit copied to clipboard

[Bug report] Pose Detection in an on demand module crashes when the client is fetched

Open vivascu opened this issue 2 years ago • 3 comments

Describe the bug When trying to init the pose detection client from a downloaded dynamic module with:

PoseDetection.getClient(options)

The application crashes with the following exception:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{XXX}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.google.mlkit.vision.pose.internal.zza.get(java.lang.Object)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3686)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3823)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7886)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object com.google.mlkit.vision.pose.internal.zza.get(java.lang.Object)' on a null object reference
        at com.google.mlkit.vision.pose.internal.PoseDetectorImpl.<init>(com.google.mlkit:pose-detection-common@@18.0.0-beta2:1)
        at com.google.mlkit.vision.pose.internal.PoseDetectorImpl.newInstance(com.google.mlkit:pose-detection-common@@18.0.0-beta2:2)
        at com.google.mlkit.vision.pose.PoseDetection.getClient(com.google.mlkit:pose-detection-common@@18.0.0-beta2:2)
        at xxxx.DownloadedActivity.onCreate(DownloadedActivity.kt:31)
        at android.app.Activity.performCreate(Activity.java:8268)
        at android.app.Activity.performCreate(Activity.java:8247)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1371)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3667)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3823) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loopOnce(Looper.java:201) 
        at android.os.Looper.loop(Looper.java:288) 
        at android.app.ActivityThread.main(ActivityThread.java:7886) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 

Expected behavior Pose detection client is fetched.

SDK Info:

  • com.google.mlkit:pose-detection:18.0.0-beta2

vivascu avatar Jul 28 '22 13:07 vivascu

Hi vivascu,

Just to clarify, did you already follow this instruction for ML Kit dynamic feature module use case and add 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta2' dependency to your BASE module?

ai-plays avatar Aug 01 '22 17:08 ai-plays

Also, when (in terms of App or Activity or Fragment lifecycle) did you call "PoseDetection.getClient(options)"?

ai-plays avatar Aug 01 '22 17:08 ai-plays

Hi ai-plays,

I followed the exactly the instructions you mention and added the support library to the base module.

And I try to get the client in the PoseDetection.getClient(options) in the onCreate() method of the downloaded activity.

vivascu avatar Aug 01 '22 17:08 vivascu

Fixed by deferring the initialising of the MlKitContext to the point when we create the downloaded activity.

An example can be found my ML Kit On demand project.

vivascu avatar Aug 25 '22 14:08 vivascu