googlesamples / mlkit

A collection of sample apps to demonstrate how to use Google's ML Kit APIs on Android and iOS
Apache License 2.0
3.5k stars 2.92k forks source link

Text Recognition & Translation getClient() Error in dynamic feature module #330

Open DorisHYC opened 3 years ago

DorisHYC commented 3 years ago

I'm working on a feature utilizing Ml Kit text recognition and Translation library. For app size concern, I moved the implementation to a dynamic delivered module, and running TextRecognition.getClient() start to give the following error:

Attempt to invoke virtual method 'com.google.mlkit.vision.text.TextRecognizer com.google.mlkit.vision.text.internal.zzk.zza()' on a null object reference

The same implementation is working properly on the regular module. And I have already included implementation 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta1 in my base apk. Can someone help to figure out what I'm missing? Thank you!

cs-googler commented 3 years ago

Hi, which version of the TextRecognition sdk did you use? The support for dynamic feature delivery was added in 16.2.0.

DorisHYC commented 3 years ago

I'm using 16.3.0

cs-googler commented 3 years ago

I tested with 'com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta1' in the base apk and 'com.google.android.gms:play-services-mlkit-text-recognition:16.3.0' in the dynamic feature module apk but could not repro your issue. Do you have your project hosted somewhere for me to take a look?

DorisHYC commented 3 years ago

Sorry unfortunately I don't. Just wanna double check tho, is there anything else I need to do to load the mlkit library dyanmically except for adding com.google.mlkit:playstore-dynamic-feature-support:16.0.0-beta1 to the base apk?

zhouyiself commented 2 years ago

I think adding playstore-dynamic-feature-support is the only required step. https://developers.google.com/ml-kit/tips/reduce-app-size#advanced_move_optional_ml_features_to_dynamic_feature_modules

Agono0 commented 2 years ago

I have the same problem with new versions, I switch to 16.3.0 also same problem.... Here's the full error

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ne.test/ com.ne.test.MainActivity}:

java.lang.NullPointerException: Attempt to invoke virtual
method 'com.goog le.mlkit.vision.text.TextRecognizer com.google.mlkit.vision.text.internal.zzk.zza(com.google.mlkit.vision.text.TextRecognizerOptionsInterface)' on a null object reference
at
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3139)
at
android.app.Activity Thread.handleLaunchActivity (Activity Thread.java:3282)
at
android.app.servertransaction.LaunchActivityltem.execute(Launch Activityltem.java:78) at
android.app.servertransaction.Transaction
Executor.executeCallbacks(TransactionExe cutor.java:108)
at
android.app.servertransaction.Transaction Executor.execute(TransactionExecutor.java:
68)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1970)
android.app.ActivityThread.main(ActivityThread.java:7156) at java.lang.reflect.Method.invoke(NativeMethod)
at
com.android.internal.os.Runtimelnit$Metho
dAndArgsCaller.run(Runtimelnit.java:494) at com.android.internal.os.ZygoteInit.main(Zygotelnit.java:975)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.g oogle.mlkit.vision.text. TextRecognizer com.google.mlkit.vision.text.internal.zzk. zza(com.google.mlkit.vision.text.TextRecognizerOptions Interface)' on a null object reference
at
com.google.mlkit.vision.text.TextRecognition.getClient(com.google.android.gms:play-services-mlkit-textrecognition@@16.3.0: 5)
at
com.ne.test.MainActivity.initializeLogic(MainActivity.java:148)
at
com.ne.test.MainActivity.onCreate(MainActivity.java:97)

Anyway I try the above solution but not working... Any solution ? Thanks in advance.

LeviMarvin commented 1 year ago

I have the same problem and using the latest version.