ML Kit vs. ZXing – comparing two popular barcode scanning libraries

Johanna November 21, 2024 17 mins read
app store

Over the years, many software solutions have emerged to overcome the limitations of traditional laser barcode scanners. They range from commercial barcode scanner SDKs and APIs to community-developed libraries – and they are not all created equal. When the goal is a smoothly-running barcode scanner app, choosing from this sea of possibilities can be daunting. 

In this article, we will comprehensively compare two of the most popular barcode scanner libraries and discuss their advantages and disadvantages: This is ML Kit vs. ZXing.

What to keep in mind when building a mobile barcode scanner app

We’ll start with a brief overview of the key considerations for mobile barcode scanning and how our contenders shape up. After that, we’ll compare the two libraries in detail.

💡 Key findings

Supported platforms:

  • ML Kit supports both Android and iOS
  • ZXing supports Android and is implemented in Java

Supported barcode types:

  • ML Kit supports many common barcode formats (fewer than ZXing)
  • ZXing supports most standard barcode formats

Performance:

  • ML Kit reputedly performs well
    • Potential reliability issues with dense barcodes
    • Low camera quality impacts scan accuracy
    • Bundled version substantially increases the app size
  • ZXing
    • Unfavorable scanning conditions may hurt scan accuracy
    • More recent device models might struggle with performance due to compatibility issues

Maintenance and updates:

  • ML Kit is regularly updated
  • ZXing is in maintenance mode

Customization:

  • ML Kit offers a customizable UI. The barcode detection model is proprietary and cannot be modified
  • ZXing is easily customizable, given users adapt the codebase themselves

Limitations:

  • ML Kit
    • ML Kit’s unbundled version requires Google Play services
    • ML Kit supports fewer symbologies
    • Regular updates require maintenance effort
    • Data privacy concerns could cause issues in Europe
  • ZXing
    • Not in active development
    • Complex integration requires deeper knowledge of library architecture
    • Copying ZXing’s barcode scanner UI too closely is a potential trademark violation

ML Kit vs. ZXing: A detailed comparison

ML Kit gives mobile developers access to some of Google’s machine-learning models. It contains several ready-to-use APIs for purposes such as translation, handwriting recognition, or face detection – and barcode scanning. The barcode scanning API works both with bundled models and unbundled ones.

ZXing (pronounced “zebra crossing”) is an open-source barcode generation and scanning library. It is currently in maintenance mode, only accepting security patches from the developer community. 

Both ML Kit and ZXing are popular barcode scanning libraries. However, they seriously differ in terms of performance and ease of integration. 

We’ll now delve deeper into the two libraries and compare them point by point.

Supported platforms

When building a barcode scanner app, the choice of operating system is one of the first aspects to consider because it directly impacts the potential audience. To ensure the scanning library runs at all, let alone smoothly, it should have good support for the platforms in question.

ML Kit supports both Android and iOS. However, developing for native iOS will require installing CocoaPods since it is the only officially supported method for integrating ML Kit into iOS applications.

Originally, ZXing was only available for native Android development and was implemented in Java. Thanks to its developer community, however,  several third-party ports are available to make it run on iOS devices. Integrating them can be complex, though, and necessitates a thorough understanding of the library’s architecture. 

Supported barcode types

The next requirement when building a barcode scanner app is support for all the barcode types that the use case demands. Today, there are approximately 30 different types of barcodes in common use, and few barcode scanners support them all. ML Kit and ZXing are no exception. 

There are two broad categories of barcode symbologies: linear barcodes (1D barcodes), which typically represent numeric data, and 2D barcodes, among them QR codes and Data Matrix codes. 

Let’s have a look at the respective supported barcodes:

ML Kit covers most of the standard barcodes, but fewer than ZXing. Notably, it lacks support for several common retail, logistics, and shipping barcodes: UPC/EAN extensions, MaxiCode, and the DataBar/RSS symbologies.

ZXing supports a larger range of product, industrial, and 2D barcode symbologies.

ML Kit does have an advantage when it comes to 2D barcodes: It can automatically parse structured data stored in such barcodes, such as URLs, contact information, or email addresses. This allows users to extract multiple pieces of information from a single barcode in a human-readable format, without a separate parsing step.

Performance

After platform and barcode support, scanning performance is the next key aspect to consider when choosing a barcode scanner library. 

There are several factors that go into performance. Depending on the scenario the barcode scanner will be used in, scanning speed, accuracy, or overall reliability can be paramount. Many real-world use cases involve less-than-ideal scanning conditions, such as poor lighting or damaged barcodes. 

This makes it difficult to evaluate how well a scanning library performs overall, or in a particular scenario – not without extensive testing. 

That said, listening to what app developers themselves have to say in relevant online spaces can grant us valuable insights into how ML Kit and ZXing generally perform.

ML Kit

The general tenor on ML Kit is that it performs well, with particular praise for working regardless of scanning position. Unlike some other options, ML Kit runs offline on the mobile device, and therefore does not suffer from connectivity issues.

Developers have, however, reported certain issues on GitHub and other platforms. Much of the criticism focuses on the following three areas: Certain dense barcodes, app size, and general accuracy issues. 

Dense barcodes might challenge ML Kit

Two of ML Kit’s 12 supported barcodes seem to be troublemakers: The PDF417 barcode, which is commonly used in transport and inventory management, and the EAN-13 barcode, best known as the typical retail barcode outside the U.S. 

Some developers have reported that these dense barcodes can’t be scanned or that the barcode scanner performs inconsistently and slowly, sometimes even presenting incorrect results. 

There are two ways of mitigating this issue: First, setting a higher resolution for the input image, though this requires additional configuration. Second, setting the barcode format before scanning. The latter can prove troublesome in applications where several types are common: In inventory management, for instance, large amounts of data may be stored in different barcode types. The user would then have to be able to identify the barcode they are about to scan, and configure their app accordingly. 

Scanning accuracy of ML Kit impacted by camera quality

Mobile barcode scanners detect and scan barcodes using the device camera. Camera quality, however, can differ across the wide range of available mobile devices. 

Generally, Google recommends using a higher-resolution image stream (1280×720 or 1920×1080). This makes barcodes scannable from a larger distance and usually provides a decent performance for real-time scanning. 

Where latency is critical, performance can be improved by capturing the image at a lower resolution, provided that the barcode makes up most of the input frame. Users will have to adjust their hand movements accordingly, and hold the camera fairly close to the code.

Using a camera’s native resolution to capture input, conversely, is not recommended. Doing so produces large images, which might result in poor latency but without any benefit to accuracy. 

For an accurate scan, Google recommends the smallest unit of a barcode (one line or one square) to be at least 2 pixels wide and tall.

Poor image focus can also hurt scan accuracy, and is a known problem with some camera models. In this case, it may be best to ask the user to recapture rather than to accept ML Kit’s output.

App size

The bundled version of ML Kit increases the app size by about 2.4 MB, which means longer download times and consumes more storage. The unbundled version adds about 200 KB to the app size, but depends on Google Play Services, reducing the range of devices the app can be used on.

ZXing

ZXing was originally developed for Android as a Java implementation. The community has since developed a number of ports, such as ZXing Flutter, which have made it available for cross-platform development. 

Its weaknesses are broadly the same as those of ML Kit, as are some of the mitigations.

Small barcodes and recommendations

Barcode scanner apps with ZXing may struggle with poorly lit or damaged barcodes. Another common issue is poor recognition of smaller barcodes, which the library can fail to decode altogether. 

There are some configuration options to improve recognition rates and accuracy: For one, it’s possible to allow users to specify what barcode type they are about to scan. For another,  limiting the scan area to a portion of the full image and using an appropriate image resolution can help balance speed and accuracy.

Inconsistent performance and compatibility

Finally, there are reports that ZXing’s performance can differ strongly between device models. On more recent phone models, in particular, ZXing appears to suffer from performance issues. Given the lack of active development, compatibility issues, and bugs will likely present a growing problem.

All this has to be considered before basing a more extensive project on ZXing, such as a commercial barcode scanner app. It is likely not an appropriate choice for high-volume or mission-critical scanning applications.

Integration and ease of use

Integrating ML Kit is generally considered to be uncomplicated. Detailed API references, sample code, and integration guidelines are publicly available – code labs and tutorials round out the comprehensive documentation.

The original ZXing library also comes with good documentation, guides, and sample code, making integration relatively straightforward. The same cannot necessarily be said of the community-written ports. To integrate one of the ported versions effectively, developers will need to be savvy in the library and the languages and frameworks used.

Maintenance and updates

Since ML Kit is backed by Google, users can count on regular updates – at least for the near future. Implementing these bug fixes and feature improvements requires an ongoing maintenance effort, as with any external dependency. At the same time, ML Kit’s future is not guaranteed: Google is infamous for killing off projects, with around 300 services in its graveyard to date.

ZXing is a community-driven open-source project, with all the advantages and disadvantages this entails. It is now officially in maintenance mode and no longer under active development. Although the core library remains functional, it receives no feature updates, and thus no support for new mobile platforms or barcode symbologies. Community-contributed patches – bug fixes and minor enhancements – are still occasionally accepted, but any substantial improvements will have to be developed in-house.

Community and support

Both libraries have an active community. ZXing’s open-source users engage mainly on GitHub, where they discuss and share new ports. Discussions of ML Kit, which is a closed-source project, happen chiefly in its own StackOverflow tag. Here, devs can ask questions and get help from community members and the ML Kit team itself.

Naturally, neither project offers the professional, personal, and, above all, timely support that users of a paid solution can expect.

Customization 

Barcode scanner libraries vary widely in their customizability – and even different components may be more or less open to adaptation.

ML Kit offers a customizable user interface: Developers can build a custom viewfinder (or aiming reticle) and add visual or haptic feedback when a barcode is scanned successfully. 

However, the underlying machine-learning model for barcode detection is proprietary and cannot be retrained or modified. If ML Kit does not support a barcode, the format cannot simply be added. If it has problems with particular barcodes, there is no way to patch it. This imposes certain limitations on a barcode scanner app built on it. This may cause issues if the choice and the generation of the barcodes is up to third parties.

ZXing, due to its nature as an open-source library, is deeply customizable. However, users who want to adapt the codebase or extend it with new features will need to fork the code and are responsible for maintaining their own version.  

Cost

ML Kit is offered by Google for free, although this also means that its functionality – and continued availability – is entirely dependent on Google.

ZXing is free and open-source software, meaning it comes at no cost. 

Neither project, however, provides professional support, making integration and maintenance costs unpredictable.

Limitations 

In addition to the performance issues already discussed above, we have discovered a number of further limitations while comparing ML Kit and ZXing. 

ML Kit

First off, the unbundled version of ML Kit requires Google Play Services, an obstacle for smart devices that lack it. Bundling ML Kit with the app ensures it can be widely used, but increases its size.

The ML Kit API doesn’t recognize barcodes in the following forms:

  • 1D barcodes with only one character, common in warehousing (for simple sorting or basic item identification in closed systems).
  • ITF barcodes with fewer than six characters to reduce the risk of false positive reads. 
  • Code 128 barcodes with FNC2, FNC3, or FNC4 function codes. 
  • QR codes generated in ECI mode. This mode enables character sets and data interpretations beyond the default coding, e.g., characters from different languages and writing systems.
  • GS1 DataBar codes, which are widely used in retail. These symbologies have several advantages over the traditional UPC and EAN codes, including higher data density. 
  • Additionally, ML Kit will only read up to ten barcodes per API call, regardless of how many are present on the image frame.

More generally, large numbers of API requests can impact the speed of the app. In some use cases, numerous barcodes have to be scanned consecutively. Here, ML Kit may slow down the app workflow.

As mentioned above, the smallest unit of a barcode should be at least 2 pixels wide and tall. For dense formats such as PDF417, which have very small modules, this means greater pixel dimensions are needed for reliable scans. 

This is not the only barcode format that can give ML Kit trouble: There are some reports of the ML Kit library producing incorrect results on EAN-13 barcodes. 

Data privacy regulations in Europe

Governments are tightening privacy regulations, and app developers must adapt. Generally, ML Kit can be considered to be compliant with data and privacy regulations, as data is processed entirely on-device. Still, ML Kit does collect metrics data for diagnostic and analytics purposes, such as device information, application information, performance metrics, and API configurations. This is fine as long as app users are notified as applicable law requires. 

There is, however, one snag to using ML Kit to build a barcode scanner app in Europe. All businesses who want to offer a product or service in the European Union must comply with the General Data Protection Regulation (GDPR), a comprehensive data privacy and security law. The issue is that Google might collect IP addresses when ML Kit runs on iOS and Android devices, which is problematic under the GDPR if the data is sent outside the EU. 

Developers must be aware that, to operate under European law, they must ensure that an app accurately discloses how it collects, shares, and secures user data.

ZXing

One of the main limitations of ZXing is the lack of active development. The open-source solution is currently in maintenance mode, which can lead to unresolved bugs and compatibility issues accumulating. This makes ZXing less reliable for commercial applications, and even a potential security risk. 

Additionally, integrating ZXing can be complex if developers are not familiar with the library’s architecture, potentially resulting in longer development times and more bugs. This could negatively affect the user experience in an enterprise-scale implementation. 

All this is why, when planning to build a commercial app with many end users, you may want to consider a commercial barcode scanner SDK that offers more consistent performance, better device compatibility, and ongoing support and updates.

Licensing considerations and UI

ZXing is released under the Apache License 2.0, which generally allows commercial use. However, such apps do have to comply with the Apache License terms, such as including a copy of the license, stating changes to the code, and preserving copyright notices. 

Notably, the License does not grant trademark rights. In practice, this means that developers cannot closely copy the characteristic ZXing barcode scanner UI. The library’s core developers have pursued such trademark violations in the past. 

And the winner is…?

Both ML Kit and ZXing offer reliable barcode scanning, though with some caveats. Which – if any – of the two is the right choice for a barcode scanner app depends on the use case, both present and future.

ZXing supports more barcodes than ML Kit, and for ML Kit, there have been reports that some of the supported barcodes can be troublesome to scan. On the other hand, ML Kit generally performs more smoothly and has a bigger support system, backed as it is by Google, and receives regular updates. 

This makes ML Kit a suitable choice for commercial barcode scanner apps, provided it can meet the requirements for performance, supported barcode types, and accuracy. Proper configuration will be vital to getting the best results for as many users as possible, especially when it comes to optimizing the capture of the input images. 

ZXing, on the other hand, is a decent choice for private projects where stability is not crucial and no success depends on it. For commercial app usage, it’s preferable to rely on a barcode scanner SDK that offers more consistent performance, better device compatibility, and ongoing updates and support.

Both barcode scanner APIs come for free – but without comprehensive support systems.

The alternative for enterprise solutions: Scanbot Barcode Scanner SDK

Are you looking to build a commercial barcode scanner app? Then, we would like you to meet the Scanbot Barcode Scanner SDK

The Scanbot Barcode Scanner SDK scans all common 1D and 2D barcodes. It also supports a range of more specialized barcodes and takes only 0.04 seconds per scan. This enterprise-grade scanning solution comes at a flat annual fee, with no regard to how often and on how many devices it is used.

At Scanbot SDK, we are constantly improving the performance of our Barcode Scanner SDK. It not only delivers rapid, accurate scans even in challenging conditions but also advanced features such as batch-scanning. 

The Scanbot Barcode Scanner SDK supports iOS, Android, Web, Windows, Linux, and all common cross-platform frameworks, including Flutter, React Native, and .NET MAUI. It comes with Ready-to-Use UI components for a complete, pre-built scanning interface, making implementation a breeze. These components are also deeply customizable. Our SDK works entirely offline, without any server connection or usage tracking, ensuring complete data security. 

Constant support offered by a Customer Success team, expert integration assistance, and direct chat support for troubleshooting by our developers rounds out our solution. The enterprise-grade support ensures that even when challenges arise during integration, they will be solved quickly and effortlessly. If you have other special requirements, simply ask – our team of experts is happy to help.

Ready to find out more? Explore the Scanbot Barcode Scanner SDK and try it out.