我们开发了一个库,其中使用了Android Mobile Vision API来检测用户的面部信息。以下问题仅在Lenovo Tab E7 和 Billow X703 上出现。
我们正在使用Google Play Services 17.0.2。
我们已经检查并尝试了以下步骤:
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()
是否返回false。显示的异常如下:
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 Services 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互联网连接以及适当的互联网权限。