找不到Android Mobile Vision API库

时间:2019-05-22 16:07:14

标签: java android google-play-services vision

我们开发了一个库,该库除其他外还使用Android Mobile Vision API来检测用户的面部。仅在 Lenovo Tab E7 Billow 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();
    }

当要构建人脸检测器时,会发生异常(请参见下文)。接着,代码检查是否返回了false的检测器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"
  • Internet连接。该设备具有有效的WiFi互联网连接并具有适当的互联网权限。

在任何情况下,该库在其他设备上均可正常运行。在上述设备上,它只有在恢复出厂设置后首次部署应用程序时才能工作。

1 个答案:

答案 0 :(得分:2)

我正在使用Huawei P30 pro,并且遇到了同样的问题。在尝试了Internet中找到的所有方法之后,事实证明该问题是由Google Play服务版本不最新引起的。 使用 Google Play服务版本20.18.17 ,应用无法找到Android Vision模块,但是将其更新到版本20.36.15 后,它可以正常工作!