Skip to content

About

Unity Native Plugin for Scanning QRCodes on Android

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

unity_qrscanner_android

Android-native QR scanner plugin for Unity. Wraps Google ML Kit's barcode scanner — the same decoder Android's stock Camera app uses.

Replaces ZXing.NET in Unity Android projects that need production-grade QR decoding (handles perspective distortion, low contrast, slight blur, custom-designed QRs — the cases ZXing.NET fails on).

Build

CI builds the AAR on every push. To build locally:

gradle :library:assembleRelease

Output: library/build/outputs/aar/library-release.aar.

(If you don't have Gradle installed system-wide, run gradle wrapper once to generate ./gradlew.)

Use in Unity

  1. Drop library-release.aar into Assets/Plugins/Android/.
  2. Drop unity/MLKitQRScanner.cs into your Unity project (or copy its contents).
  3. Either commit unity/Dependencies.xml to your project (so External Dependency Manager auto-resolves the ML Kit dependency), or add this line manually to your mainTemplate.gradle:
implementation 'com.google.mlkit:barcode-scanning:17.3.0'
  1. Call from C#:
using XRProj.QRScanner;

byte[] grayscaleBuffer = ...; // R8 / Gray8 single-channel
int width = 640, height = 480;

MLKitQRScanner.Scan(grayscaleBuffer, width, height, result =>
{
    if (result != null)
        Debug.Log($"QR decoded: {result}");
    else
        Debug.Log("no QR found in frame");
});

Why ML Kit, not ZXing

ZXing.NET (the .NET port still floating around in Unity projects) is in slow maintenance and struggles with real-world handheld captures. ML Kit's barcode scanner is what Google ships in production camera apps — actively developed, hardware-accelerated where available, and far more tolerant of imperfect input.

For an apples-to-apples test, scan the same poorly-lit QR with this plugin vs ZXing.NET; ML Kit reads it, ZXing returns null.

About

Unity Native Plugin for Scanning QRCodes on Android

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages