Google 未找到视觉条码库

Google Vision barcode library not found

我正在尝试使用 Google Play Services (Vision) 中的新功能将 QR 码扫描添加到我的应用程序中。但是当我 运行 我的应用程序时,我得到这个:

I/Vision﹕ Supported ABIS: [armeabi-v7a, armeabi]
D/Vision﹕ Library not found: /data/data/com.google.android.gms/files/com.google.android.gms.vision/barcode/libs/armeabi-v7a/libbarhopper.so
I/Vision﹕ Requesting barcode detector download.

我已按照教程声明条形码依赖项:

<meta-data
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="barcode" />

我尝试重新安装应用程序并重新启动 phone,但没有任何帮助。

使用Google Play Services 7.8,设备上安装的版本是7.8.11。

compile 'com.google.android.gms:play-services-vision:7.8.0'

用于创建条形码检测器的代码:

boolean initBarcodeDetector() {
    final BarcodeTrackerFactory barcodeTrackerFactory = new BarcodeTrackerFactory(this);
    final MultiProcessor<Barcode> multiProcessor = new MultiProcessor.Builder<>(barcodeTrackerFactory)
            .build();
    barcodeDetector = new BarcodeDetector.Builder(this)
            .build();
    barcodeDetector.setProcessor(multiProcessor);

    if (barcodeDetector.isOperational() == false) {
        Toast.makeText(this, R.string.barcode_not_operational, Toast.LENGTH_LONG).show();
        finish();
        return false;
    }

    return true;
}

上面关闭 returns false 并完成 activity 因为 barcodeDetector.isOperational() returns false.

基于此处的文档: https://developers.google.com/android/reference/com/google/android/gms/vision/package-summary and here: https://developers.google.com/android/reference/com/google/android/gms/vision/Detector#isOperational()

文档:

public boolean isOperational()

Indicates whether the detector has all of the required dependencies available locally in order to do detection.

When an app is first installed, it may be necessary to download required files. If this returns false, those files are not yet available. Usually this download is taken care of at application install time, but this is not guaranteed. In some cases the download may have been delayed.

If your code has added a processor, an indication of the detector operational state is also indicated with the detectorIsOperational() method. You can check this in your app as it processes detection results, and can convey this state to the user if appropriate.

Returns •true if the detector is operational, false if the dependency download is in progress

public boolean detectorIsOperational()

Returns true if the detector is operational, false if it is not operational. In the non-operational case, the detector will return no results.

A detector may be non-operational for a while when starting an app for the first time, if a download is required to obtain the associated library and model files required to do detection.

您的设备似乎需要通过 Google Play 服务完成库的下载,以便您的应用程序立即运行。

基于 Google 示例(来源中的评论):

        // Note: The first time that an app using the barcode or face API is installed on a
        // device, GMS will download a native libraries to the device in order to do detection.
        // Usually this completes before the app is run for the first time.  But if that
        // download has not yet completed, then the above call will not detect any barcodes
        // and/or faces.
        //
        // isOperational() can be used to check if the required native libraries are currently
        // available.  The detectors will automatically become operational once the library
        // downloads complete on device.

https://github.com/googlesamples/android-vision/blob/master/visionSamples/multi-tracker/app/src/main/java/com/google/android/gms/samples/vision/face/multitracker/MultiTrackerActivity.java#L156

它在我清除缓存并释放一些 space 后开始工作。我有 "only" 400mb 免费 space 并且没有错误消息表明。

我也遇到过这种情况,在我的一个测试设备上找不到视觉库,虽然每次启动应用程序时控制台都会显示对库的请求,但从未完成。我在 Nexus 4,5 摩托罗拉 X2、三星 S 2-6 和各种其他设备上进行了测试,S5 是唯一存在问题的设备。有足够的免费 space 超过 2Gb,在硬重置设备后扫描立即按预期工作。

我也有过同样的经历。 (抱歉,我无法评论添加我的案例,因为我只有 1 个代表) 我将 Nexus 5 (2013) 与 marshmallow (6.0) 一起使用。 我从 1gb 免费 space 开始,但没有工作,也没有在 2gb 下工作。 我最终释放了另外 1gb(因此释放了 3gb space)然后它起作用了。

Google 已确认他们将很快修复一个错误,这会阻止您在某些情况下使用 barcode/face-detection (link here) 的库:

  • A service required by Mobile Vision is now disabled due to a serious bug in that service. This will prevent users who have not already used face or barcode detection from using those features. We do not recommend adding new Mobile Vision features to your app until this issue is fixed.
  • For apps that already use Mobile Vision features, check FaceDetector.isOperational() or BarcodeDetector.isOperational() to confirm detector readiness before using the face or barcode detector.

Google 的 github 示例 repo 中报告的一些问题中也写了它:

https://github.com/googlesamples/android-vision/issues

示例(here):

There is a known issue with the new version of GMSCore (v9) that was just released today.

Mobile Vision 操作已在 Google Play Services v9.2 中恢复 https://developers.google.com/vision/release-notes#google_play_services_92

Release Notes

Here are the updates to the Mobile Vision API, corresponding to the Google Play Services releases.

Google Play Services 9.2

Bug Fixes

Mobile Vision operation is restored in Google Play Services v9.2. Users with the new version will be able to download the required files and make use of application features powered by Mobile Vision. The Google Play Services update also includes a configuration update as part of the fix for Mobile Vision. Normally this is updated once every several days, but it will also occur on phone reboot (though this it is throttled, so this is not guaranteed to update the configuration). Since file download errors can still occur (e.g. if there is insufficient storage on the device), we advise Google Play Services developers to call FaceDetector.isOperational() or BarcodeDetector.isOperational() to check for detector readiness and degrade feature operation accordingly.

2020 年 9 月: 这个版本有:

implementation 'com.google.android.gms:play-services-vision:20.1.2'