java - 未找到 Android 移动视觉 API 库

标签 java android google-play-services vision

我们开发了一个库,除其他外,它使用 Android Mobile Vision API 来检测用户的面部。以下问题仅出现在 联想 Tab E7 浪涛 X703 .

    private void createCameraSource() {

        Context context = getApplicationContext();
        FaceDetector detector = new FaceDetector.Builder(context)
                .setProminentFaceOnly(true)
                .setTrackingEnabled(true)
                .setClassificationType(com.google.android.gms.vision.face.FaceDetector.ALL_CLASSIFICATIONS)
                .setMode(com.google.android.gms.vision.face.FaceDetector.ACCURATE_MODE)
                .setMinFaceSize(minFaceSize)
                .build();   // <--- HERE IS THE EXCEPTION

        detector.setProcessor(
                new MultiProcessor.Builder<>(new GraphicFaceTrackerFactory())
                        .build());

        if (!detector.isOperational()) {
            // Note: The first time that an app using face API is installed on a device, GMS will
            // download a native library 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 faces.
            //
            // isOperational() can be used to check if the required native library is currently
            // available.  The detector will automatically become operational once the library
            // download completes on device.
            Log.w(TAG, "Face detector dependencies are not yet available.");

            // Check for low storage.  If there is low storage, the native library will not be
            // downloaded, so detection will not become operational.
            IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
            boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;

            if (hasLowStorage) {
                Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
                Log.w(TAG, getString(R.string.low_storage_error));
            }
        }

        mCameraSource = new CameraSource.Builder(context, detector)
                .setFacing(CameraSource.CAMERA_FACING_FRONT)
                .setRequestedFps(fps)
                .build();
    }

当它即将构建人脸检测器时,会发生异常(见下文)。接下来,代码检查检测器 isOperational() ,返回假。显示的异常是:
2019-05-22 16:09:48.128 27557-27557/com.xxx.xxx.xxx W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.face not found.
2019-05-22 16:09:48.134 25402-25415/? W/ProviderHelper: Unknown dynamite feature vision.dynamite.face
2019-05-22 16:09:48.140 27557-27557/com.xxx.xxx.xxx I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.face:0 and remote module com.google.android.gms.vision.dynamite.face:0
2019-05-22 16:09:48.140 27557-27557/com.xxx.xxx.xxx D/FaceNativeHandle: Cannot load feature, fall back to load whole module.
2019-05-22 16:09:48.142 27557-27557/com.xxx.xxx.xxx W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite not found.
2019-05-22 16:09:48.144 25402-25415/? W/ProviderHelper: Unknown dynamite feature vision.dynamite
2019-05-22 16:09:48.149 27557-27557/com.xxx.xxx.xxx I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite:0 and remote module com.google.android.gms.vision.dynamite:0
2019-05-22 16:09:48.154 27557-27557/com.xxx.xxx.xxx E/FaceNativeHandle: Error Loading module
    com.google.android.gms.dynamite.DynamiteModule$LoadingException: No acceptable module found. Local version is 0 and remote version is 0.
        at com.google.android.gms.dynamite.DynamiteModule.load(Unknown Source:8)
        at com.google.android.gms.internal.vision.zzm.zzq(Unknown Source:28)
        at com.google.android.gms.vision.face.internal.client.zzc.<init>(Unknown Source:3)
        at com.google.android.gms.vision.face.FaceDetector$Builder.build(Unknown Source:40)
        at com.xxx.xxx.xxx.activities.Activity1.createCameraSource(Activity1.java:128)
        at com.xxx.xxx.xxx.activities.Activity1.onCreate(Activity1.java:111)
        at android.app.Activity.performCreate(Activity.java:7023)
        at android.app.Activity.performCreate(Activity.java:7014)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
2019-05-22 16:09:48.154 27557-27557/com.xxx.xxx.xxx W/FaceNativeHandle: Native handle not yet available. Reverting to no-op handle.

在手机上安装应用程序后,AndroidManifest.xml 中的一行应通知移动应用程序为特定设备下载适当的人脸检测库。但是,这似乎仅在设备重置为出厂设置和首次安装应用程序时才会发生。例如,如果我通过 Android Studio 重新安装应用程序,则应用程序无法找到特定模块。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.xxx.xxx"
    android:installLocation="auto">

    <uses-permission
        android:name="android.permission.INTERNET"
        android:required="true" />

    <uses-permission-sdk-23
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:required="true" />
    <uses-permission-sdk-23
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:required="true" />

    <uses-permission
        android:name="android.permission.CAMERA"
        android:required="true" />
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.front" />
    <uses-feature android:name="android.hardware.camera.autofocus" />

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true">
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.gms.vision.DEPENDENCIES"
            android:value="face" />

        <activity
            android:name=".activities.Activity1"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.Activity2"
            android:screenOrientation="portrait" />
        <activity
            android:name=".activities.Activity3"
            android:screenOrientation="portrait" />
    </application>

</manifest>

我们正在使用 Google Play 服务 17.0.2

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

我们已经检查并尝试了以下方法:
  • 清除数据和缓存 Google Play 服务/Google Play 商店/移动应用程序。
  • 空闲空间 .该设备有 8GB 内存,其中 3.82GB 是可用空间。
  • 存储权限 .该应用程序具有存储权限和android:installLocation="auto"
  • 互联网连接 .该设备具有有效的 WiFi 互联网连接和适当的互联网权限。

  • 该库在任何情况下都可以在其他设备上完美运行。在上述设备上,它仅在恢复出厂设置后首次部署应用程序时工作。

    最佳答案

    我正在使用华为 P30 pro 并且遇到了同样的问题。尝试了网上找到的所有方法后,发现问题是由于Google Play Services版本不是最新的。
    Google Play 服务版本 20.18.17 , 应用找不到 Android Vision 模块,但更新到 后版本 20.36.15 , 有效!

    关于java - 未找到 Android 移动视觉 API 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56260986/

    相关文章:

    java - 在双引号外的逗号上拆分。如果是单引号则忽略双引号

    java - 如何使用 JpaRepository 和嵌套的对象列表进行搜索?

    android - 图像叠加/与 css 重叠

    android - Admob Native 广告加载失败,错误代码为 0

    android - 使用 PendingIntent 获取位置始终返回 Null

    java - BlueJ 导入自定义类库

    java - 如何在 Spring Data Mongodb 上使用 SpEL 表达式?

    android - 将请求分成 1 MB 的 block (和 cursor.close())后,SQLiteBlobTooBigException 仍然发生

    android - 为什么在 cordova WebView 中按下后退按钮会关闭应用程序?

    android - 设备位置关闭时从 Google Play 服务获取最后已知位置