Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] MLKit.Initialize() fails with NullPointerException on Android 11 devices #777

Open
sangrao opened this issue Feb 21, 2024 · 1 comment
Assignees

Comments

@sangrao
Copy link

sangrao commented Feb 21, 2024

Describe the bug
To optimize app startup, we disabled ContentProvider and explicitly call MLKit.Initialize(). However, we observed crashes on some devices, most commonly chromebook + Android 11. Note that we have integrated with both the bundled and unblunded library.

To Reproduce
Example Steps to reproduce the behavior in sample app:

  1. Add dependency to mlkit lib specified in the SDK section below
  2. set meta-data for unbundled models
		<meta-data
			android:name="com.google.mlkit.vision.DEPENDENCIES"
			android:value="barcode,ocr" />
  1. Disable Content Provider as
    <provider android:name="com.google.mlkit.common.internal.MlKitInitProvider" android:authorities="${applicationId}.mlkitinitprovider" tools:node="remove" />
  2. In the activity, before accessing any ML kit feature invoke MLKit.Initialize(context), with context value being application context. Note, care has been taken to invoke this method only once.

Expected behavior
MLKit is initialized successfully. However, on certain devices crashlytics captured the below error

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.AbstractCollection.size()' on a null object reference
       at com.google.android.gms.internal.mlkit_vision_object_detection_bundled.zzar.<init>(com.google.mlkit:object-detection@@16.2.5:1)
       at com.google.android.gms.internal.mlkit_vision_object_detection_bundled.zzat.<clinit>(com.google.mlkit:object-detection@@16.2.5:1)
       at com.google.android.gms.internal.mlkit_vision_object_detection_bundled.zzat.zzh(com.google.mlkit:object-detection@@16.2.5:2)
       at com.google.android.gms.internal.mlkit_vision_object_detection_bundled.zzat.zzj(com.google.mlkit:object-detection@@16.2.5:1)
       at com.google.android.gms.internal.mlkit_vision_object_detection_bundled.zzot.<clinit>(com.google.mlkit:object-detection@@16.2.5:13)
       at com.google.mlkit.vision.objects.defaults.internal.DefaultObjectsRegistrar.getComponents(com.google.mlkit:object-detection@@16.2.5:17)
       at com.google.firebase.components.ComponentRuntime.discoverComponents(ComponentRuntime.java:117)
       at com.google.firebase.components.ComponentRuntime.<init>(ComponentRuntime.java:99)
       at com.google.firebase.components.ComponentRuntime.<init>(ComponentRuntime.java:46)
       at com.google.firebase.components.ComponentRuntime$Builder.build(ComponentRuntime.java:387)
       at com.google.mlkit.common.sdkinternal.MlKitContext.zza(com.google.mlkit:common@@17.3.0:9)
       at com.google.mlkit.common.MlKit.initialize(com.google.mlkit:common@@17.3.0:1)

SDK Info:

  • com.google.mlkit:object-detection:16.2.5
  • com.google.android.gms:play-services-mlkit-barcode-scanning:16.2.1
  • com.google.android.gms:play-services-mlkit-image-labeling:16.0.5
  • com.google.android.gms:play-services-mlkit-text-recognition:16.1.1

Smartphone:
Mostly Chromebook

100% on Android 11 devices

@ai-plays
Copy link
Collaborator

Thanks for the detailed info!

The object-detection 16.2.5 is a quite old version from ~3 years ago. https://developers.google.com/ml-kit/release-notes#may_25_2021

The latest version is 17.0.1.

Do you see same error logs from newer versions?

@ai-plays ai-plays self-assigned this Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@ai-plays @sangrao and others