I had the same problem. It seems to be some google bug which sometimes happen. In my case google code scanner was working one day but on the next day does not without any code change. I just deleted data of Google Play services
app. After that I got error CODE_SCANNER_UNAVAILABLE
(Required code scanner module is not available yet) see https://developers.google.com/android/reference/com/google/mlkit/common/MlKitException and this means that just wait a few seconds and try again and google code scanner will work - this is just in local development when app is not installed via play store. In usual case google installs code scanner with app if you have <meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="barcode_ui" />
in AndroidManifest.xml.
Great to debug is android app in play store https://play.google.com/store/apps/details?id=com.khandev.qrcodescanner which uses google code scanner library. You can test that when you delete play services data and install that app from play store and open it after several second later google code scanner is working so lib was pre-installed with app before first app use.
So implement manual downloading by this doc https://developers.google.com/android/guides/module-install-apis is useless. In local dev after first use you will got CODE_SCANNER_UNAVAILABLE
and later it will work whe google downloads it.
UPDATE 1: we do not recommend this lib in prod, very unreliable, we must stop using it immediatelly, it failures on many different devices (Google code scanner "Failed to scan code."). Google has reported bug but did not solve it https://issuetracker.google.com/issues/261579118
UPDATE 2: this lib is really unusable for 4 reasons:
1.) Issue https://issuetracker.google.com/issues/261579118 ignored by Google.
2.) When you get lucky and google code scanner works for you (maybe because you must delete Google Play services data which is not acceptable solution because you will lost payment card and many other google related stuff) it will stop working after several days again: I/System.out: GOOGLE CODE SCANNER: MlKitException: code: 13; constant: INTERNAL; message: Failed to scan code.
3.) Doc ( https://developers.google.com/ml-kit/vision/barcode-scanning/code-scanner#configure_your_app ) says when you add <meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="barcode_ui" />
into AndroidManifest.xml
google play store will install lib within the app. It is not true. I have tested it: installed app from play store, opened app at home screen and wait many minutes (to give google chance to download and install library) but in about 10 minutes later I navigated in app to screen when google code scanner is used and I got error CODE_SCANNER_UNAVAILABLE
( https://developers.google.com/android/reference/com/google/mlkit/common/MlKitException#CODE_SCANNER_UNAVAILABLE ) so google did not prepared it at all! Google starts downloading and installing code scanner now after first use NOT AFTER APP INSTALL as said in doc, so it is not acceptable for user to say to him to wait several seconds or minutes (depending on connection speed) and try again. I do not wish to download it manually using many additional Java/Kotlin lines of code when it should work out of the box by doc.
4.) Google in https://developers.google.com/ml-kit/vision/barcode-scanning/code-scanner approved with a benefit that your app does not need camera permission but does not say important thing that app Google Play services must have this permission. Android does not show standard dialog to grant it just show long text warning that app needs permission and user must grant it manually what could be really difficult for many users because Google Play services app is system app and on some devices (Blackberry and maybe other) is not easy find it and grant permission.