java.lang.NoClassDefFoundError:解析失败:Lcom / google / android / gms / vision / face / FaceDetector;

时间:2018-01-03 22:18:10

标签: android crash face-detection vision google-vision

我正在为使用Android人脸检测的Unity编写一个Android插件。我有插件使用旧的

android.media.FaceDetector;

面部检测器,我想将其更新为新的Google愿景API

出于某种原因,只需添加一个面部检测器变量的声明,就会导致插件一启动就崩溃。

以下是相关代码。

package com.test.camerapreview;

import android.app.Activity;
//import android.content.Context;
//import android.graphics.Bitmap;
//import android.graphics.BitmapFactory;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
//import android.media.FaceDetector;
import android.opengl.GLES11Ext;
import android.opengl.GLES20;
import android.util.Log;
//import android.util.SparseArray;
import android.view.Display;
import android.view.Surface;
//import android.view.SurfaceView;

//import com.google.android.gms.vision.Frame;
import com.google.gson.Gson;
import com.unity3d.player.UnityPlayer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

//import com.google.android.gms.common.ConnectionResult;
//import com.google.android.gms.common.GoogleApiAvailability;
//import com.google.android.gms.vision.CameraSource;
//import com.google.android.gms.vision.MultiProcessor;
//import com.google.android.gms.vision.Tracker;
//import com.google.android.gms.vision.face.Face;
import com.google.android.gms.vision.face.FaceDetector;

    public class NativeCamera implements Camera.PreviewCallback, Camera.FaceDetectionListener {

        public static NativeCamera instance;
        public static String gameObjectTargetName;
        private static Activity myActivity;

        Camera mCamera;
        int camId;
        SurfaceTexture texture;
        int nativeTexturePointer = -1;

        int unrotatedWidth;
        int unrotatedHeight;
        int rotatedHeight;
        int rotatedWidth;

        com.google.android.gms.vision.face.FaceDetector faceDetector; // Putting this here makes my app crash.

        //
        // Call this function first.
        //
        public static void Setup(String gameObjectName, Activity theActivity){
            gameObjectTargetName = gameObjectName;
            myActivity = theActivity;
            instance = new NativeCamera();
        }

    // Rest of code snipped out
}

此源的唯一区别是添加了faceDetector变量。它不会在任何地方使用。

这是我在adb logcat中看到的错误

01-03 14:00:45.798 19649-19787/? W/MDM: InstalledPackageMonitor - <--> getAppVersionForUid(-1) failed to find matching entity
01-03 14:00:46.123 19649-19787/? I/chatty: uid=10117(com.metago.astro) bmv identical 1 line
01-03 14:00:46.141 19649-19787/? W/MDM: InstalledPackageMonitor - <--> getAppVersionForUid(-1) failed to find matching entity
01-03 14:00:46.346 723-830/? I/ThermalEngine: vs_get_temperature: read[0] tsens_tz_sensor15 49000 mC, weight[0] 1
01-03 14:00:46.346 723-830/? I/ThermalEngine: vs_get_temperature: read[1] tsens_tz_sensor0 53000 mC, weight[1] -1
01-03 14:00:46.710 19649-19787/? W/MDM: InstalledPackageMonitor - <--> getAppVersionForUid(-1) failed to find matching entity
01-03 14:00:46.770 14771-14784/? I/zygote64: Waiting for a blocking GC ProfileSaver
01-03 14:00:46.792 14771-14784/? I/zygote64: WaitForGcToComplete blocked ProfileSaver on AddRemoveAppImageSpace for 21.469ms
01-03 14:00:47.348 723-830/? I/ThermalEngine: vs_get_temperature: read[0] tsens_tz_sensor15 49000 mC, weight[0] 1
01-03 14:00:47.348 723-830/? I/ThermalEngine: vs_get_temperature: read[1] tsens_tz_sensor0 52000 mC, weight[1] -1
01-03 14:00:47.492 2286-2286/? I/WearableService: Wearable Services stopping
01-03 14:00:48.350 723-830/? I/ThermalEngine: vs_get_temperature: read[0] tsens_tz_sensor15 48000 mC, weight[0] 1
01-03 14:00:48.350 723-830/? I/ThermalEngine: vs_get_temperature: read[1] tsens_tz_sensor0 52000 mC, weight[1] -1
01-03 14:00:49.352 723-830/? I/ThermalEngine: vs_get_temperature: read[0] tsens_tz_sensor15 48000 mC, weight[0] 1
01-03 14:00:49.352 723-830/? I/ThermalEngine: vs_get_temperature: read[1] tsens_tz_sensor0 52000 mC, weight[1] -1
01-03 14:00:49.904 868-2419/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.tvgla.campreview/com.unity3d.player.UnityPlayerActivity bnds=[586,1508][855,1857]} from uid 10032
01-03 14:00:49.908 671-671/? D/QCOM PowerHAL: LAUNCH HINT: ON
01-03 14:00:49.909 1950-1952/? E/ANDR-PERF-OPTSHANDLER: Warning: Resource [2, 0] not supported for core 1. Instead use resource for core 0
01-03 14:00:49.909 658-2267/? I/ACDB-LOADER: ACDB AFE returned = -19
01-03 14:00:49.909 1950-1952/? E/ANDR-PERF-RESOURCEQS: Failed to apply optimization [2, 2, 0]
01-03 14:00:49.909 658-2267/? D/hardware_info: hw_info_append_hw_type : device_name = speaker
01-03 14:00:49.909 658-2267/? D/audio_hw_primary: enable_snd_device: snd_device(2: speaker)
01-03 14:00:49.909 658-2267/? D/audio_route: Apply path: speaker
01-03 14:00:49.909 658-2267/? D/audio_hw_primary: enable_audio_route: usecase(1) apply and update mixer path: low-latency-playback speaker
01-03 14:00:49.909 658-2267/? D/audio_route: Apply path: low-latency-playback speaker
01-03 14:00:49.923 671-671/? D/QCOM PowerHAL: Activity launch hint handled
01-03 14:00:49.948 868-894/? I/ActivityManager: Start proc 14820:com.tvgla.campreview/u0a324 for activity com.tvgla.campreview/com.unity3d.player.UnityPlayerActivity
01-03 14:00:49.948 658-2267/? D/audio_hw_primary: out_write: retry previous failed cal level set
01-03 14:00:49.958 14820-14820/? I/zygote: Late-enabling -Xcheck:jni
01-03 14:00:50.090 14820-14837/? D/OpenGLRenderer: HWUI GL Pipeline
01-03 14:00:50.121 14820-14837/? I/Adreno: QUALCOMM build                   : 2941438, I916dfac403
                                           Build Date                       : 10/03/17
                                           OpenGL ES Shader Compiler Version: EV031.21.02.00
                                           Local Branch                     : O18A
                                           Remote Branch                    : 
                                           Remote Branch                    : 
                                           Reconstruct Branch               : 
01-03 14:00:50.126 14820-14837/? I/Adreno: PFP: 0x005ff087, ME: 0x005ff063
01-03 14:00:50.132 14820-14837/? I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
01-03 14:00:50.133 14820-14837/? I/OpenGLRenderer: Initialized EGL, version 1.4
01-03 14:00:50.133 14820-14837/? D/OpenGLRenderer: Swap behavior 2
01-03 14:00:50.165 868-918/? I/ActivityManager: Displayed com.tvgla.campreview/com.unity3d.player.UnityPlayerActivity: +225ms
01-03 14:00:50.167 1377-1377/? I/GoogleInputMethod: onFinishInput() : Dummy InputConnection bound
01-03 14:00:50.167 1377-1377/? I/GoogleInputMethod: onStartInput() : Dummy InputConnection bound
01-03 14:00:50.173 671-671/? D/QCOM PowerHAL: LAUNCH HINT: OFF
01-03 14:00:50.192 14820-14836/? I/Unity: SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 4, Memory = 3753mb
01-03 14:00:50.192 14820-14836/? I/Unity: SystemInfo ARM big.LITTLE configuration: 2 big (mask: 12), 2 little (mask: 3)
01-03 14:00:50.192 14820-14836/? I/Unity: ApplicationInfo com.tvgla.campreview version 1.0 build 44c1fe70-80a4-4a60-8a18-207b4d37a86f
01-03 14:00:50.195 14836-14836/? W/UnityMain: type=1400 audit(0.0:91697): avc: denied { read } for name="stat" dev="proc" ino=4026532357 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc_stat:s0 tclass=file permissive=0
01-03 14:00:50.262 14820-14836/? E/Unity: Unable to find AudioPluginMsHRTF
01-03 14:00:50.263 14820-14836/? E/Unity: Unable to find AudioPluginOculusSpatializer
01-03 14:00:50.264 14820-14836/? E/Unity: Unable to find unitygar
01-03 14:00:50.264 14820-14836/? E/Unity: Unable to find libAudioPluginOculusSpatializer
01-03 14:00:50.266 14820-14836/? E/Unity: Unable to find libtango_3d_reconstruction_api
01-03 14:00:50.280 14820-14836/? D/Unity:  GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_sync GL_OES_vertex_half_float GL_OES_framebuffer_object GL_OES_rgb8_rgba8 GL_OES_compressed_ETC1_RGB8_texture GL_AMD_compressed_ATC_texture GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_OES_texture_compression_astc GL_OES_texture_npot GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_OES_texture_3D GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_QCOM_alpha_test GL_OES_depth24 GL_OES_packed_depth_stencil GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_EXT_sRGB GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_EXT_texture_type_2_10_10_10_REV GL_EXT_texture_sRGB_decode GL_OES_element_index_uint GL_EXT_copy_image GL_EXT_geometry_shader GL_EXT_tessellation_shader GL_OES_texture_stencil8 GL_EXT_shader_io_blocks GL_OES_shader_image_atomic GL_OES_sample_variables GL_EXT_texture_border_clamp GL_EXT_multisampled_render_to_texture GL_EXT_mul
01-03 14:00:50.280 14820-14836/? D/Unity: tisampled_render_to_texture2 GL_OES_shader_multisample_interpolation GL_EXT_texture_cube_map_array GL_EXT_draw_buffers_indexed GL_EXT_gpu_shader5 GL_EXT_robustness GL_EXT_texture_buffer GL_EXT_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_OES_texture_storage_multisample_2d_array GL_OES_sample_shading GL_OES_get_program_binary GL_EXT_debug_label GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_QCOM_tiled_rendering GL_ANDROID_extension_pack_es31a GL_EXT_primitive_bounding_box GL_OES_standard_derivatives GL_OES_vertex_array_object GL_EXT_disjoint_timer_query GL_KHR_debug GL_EXT_YUV_target GL_EXT_sRGB_write_control GL_EXT_texture_norm16 GL_EXT_discard_framebuffer GL_OES_surfaceless_context GL_OVR_multiview GL_OVR_multiview2 GL_EXT_texture_sRGB_R8 GL_KHR_no_error GL_EXT_debug_marker GL_OES_EGL_image_external_essl3 GL_OVR_multiview_multisampled_render_to_texture GL_EXT_buffer_storage GL_EXT_external_buffer GL_EXT_blit_framebuffer_params GL_EXT_clip_cull_distance
01-03 14:00:50.280 14820-14836/? D/Unity:  GL_EXT_protected_textures GL_EXT_shader_non_constant_global_initializers GL_QCOM_framebuffer_foveated GL_QCOM_shader_framebuffer_fetch_noncoherent GL_EXT_EGL_image_array GL_NV_shader_noperspective_interpolation

                                          [ 01-03 14:00:50.316 14820:14836 D/         ]
                                          PlayerBase::PlayerBase()

                                          [ 01-03 14:00:50.317 14820:14836 D/         ]
                                          TrackPlayerBase::TrackPlayerBase()
01-03 14:00:50.317 14820-14836/? I/libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
01-03 14:00:50.317 14820-14836/? W/AudioTrack: notificationFrames=-10 clamped to the range -1 to -8
01-03 14:00:50.319 14820-14836/? I/AudioTrack: AUDIO_OUTPUT_FLAG_FAST successful; frameCount 1536 -> 1536
01-03 14:00:50.319 14820-14836/? D/AudioTrack: Client defaulted notificationFrames to 192 for frameCount 1536
01-03 14:00:50.321 1342-1881/? D/Avrcp: AudioManager Player: ID:23 -- type:android.media.SoundPool -- u/pid:10043/1393 -- state:idle -- attr:AudioAttributes: usage=USAGE_ASSISTANCE_SONIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x0 tags= bundle=null
01-03 14:00:50.321 1342-1881/? D/Avrcp: AudioManager Player: ID:15 -- type:android.media.SoundPool -- u/pid:1000/868 -- state:idle -- attr:AudioAttributes: usage=USAGE_ASSISTANCE_SONIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x0 tags= bundle=null
01-03 14:00:50.321 1342-1881/? D/Avrcp: AudioManager Player: ID:31 -- type:android.media.SoundPool -- u/pid:1027/2374 -- state:idle -- attr:AudioAttributes: usage=USAGE_NOTIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x0 tags= bundle=null
01-03 14:00:50.321 1342-1881/? D/Avrcp: AudioManager Player: ID:2431 -- type:android.media.MediaPlayer -- u/pid:10035/8516 -- state:idle -- attr:AudioAttributes: usage=USAGE_UNKNOWN content=CONTENT_TYPE_UNKNOWN flags=0x0 tags= bundle=null
01-03 14:00:50.321 1342-1881/? D/Avrcp: AudioManager Player: ID:2447 -- type:android.media.MediaPlayer -- u/pid:10043/1393 -- state:stopped -- attr:AudioAttributes: usage=USAGE_NOTIFICATION content=CONTENT_TYPE_SONIFICATION flags=0x0 tags= bundle=null
01-03 14:00:50.321 1342-1881/? D/Avrcp: AudioManager Player: ID:2527 -- type:OpenSL ES AudioPlayer (Buffer Queue) -- u/pid:10324/14820 -- state:started -- attr:AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x0 tags= bundle=null
01-03 14:00:50.321 1342-1881/? D/Avrcp: AudioManager isPlaying: true
01-03 14:00:50.322 656-656/? W//system/bin/hw/android.hidl.allocator@1.0-service: ashmem_create_region(3840) returning hidl_memory(0x7d5f82b330, 3840)
01-03 14:00:50.323 656-656/? W//system/bin/hw/android.hidl.allocator@1.0-service: ashmem_create_region(3840) returning hidl_memory(0x7d5f82b330, 3840)
01-03 14:00:50.332 658-22045/? E/volume_listener: check_and_set_gain_dep_cal: Failed to set gain dep cal level
01-03 14:00:50.333 1342-1881/? E/Avrcp: play status change 2➡1 mPlayStatusChangedNT: 1
01-03 14:00:50.334 1342-1881/? E/bt_btif: register_notification_rsp: Avrcp device is not connected, handle: 0x0
01-03 14:00:50.334 1342-1881/? D/Avrcp: sendPlayPosNotificationRsp: Not registered or requesting.
01-03 14:00:50.334 1950-1952/? E/ANDR-PERF-OPTSHANDLER: Warning: Resource [2, 0] not supported for core 1. Instead use resource for core 0
01-03 14:00:50.334 658-9407/? I/ACDB-LOADER: ACDB AFE returned = -19
01-03 14:00:50.334 1950-1952/? E/ANDR-PERF-RESOURCEQS: Failed to apply optimization [2, 2, 0]
01-03 14:00:50.334 658-9407/? D/audio_hw_primary: enable_audio_route: usecase(5) apply and update mixer path: audio-ull-playback speaker
01-03 14:00:50.334 658-9407/? D/audio_route: Apply path: audio-ull-playback speaker
01-03 14:00:50.342 658-9407/? D/audio_hw_primary: out_write: retry previous failed cal level set
01-03 14:00:50.354 723-830/? I/ThermalEngine: vs_get_temperature: read[0] tsens_tz_sensor15 49000 mC, weight[0] 1
01-03 14:00:50.354 723-830/? I/ThermalEngine: vs_get_temperature: read[1] tsens_tz_sensor0 54000 mC, weight[1] -1
01-03 14:00:50.383 1543-1543/? D/zz: UtWallpaperService$UtEngine.onVisibilityChanged() false
01-03 14:00:50.386 1543-1543/? D/zz: UtRenderer.onNotVisible() 
01-03 14:00:50.504 2331-2331/? I/PBSessionCacheImpl: Deleted sessionId[8605084760413] from persistence.
01-03 14:00:50.533 868-1542/? I/WifiService: getWifiEnabledState uid=10048
01-03 14:00:50.550 2331-2331/? W/SearchService: Abort, client detached.
01-03 14:00:51.356 723-830/? I/ThermalEngine: vs_get_temperature: read[0] tsens_tz_sensor15 50000 mC, weight[0] 1
01-03 14:00:51.356 723-830/? I/ThermalEngine: vs_get_temperature: read[1] tsens_tz_sensor0 54000 mC, weight[1] -1
01-03 14:00:52.357 723-830/? I/ThermalEngine: vs_get_temperature: read[0] tsens_tz_sensor15 49000 mC, weight[0] 1
01-03 14:00:52.357 723-830/? I/ThermalEngine: vs_get_temperature: read[1] tsens_tz_sensor0 53000 mC, weight[1] -1
01-03 14:00:52.979 868-894/? W/SensorService: sensor 00000001 already enabled in connection 0x782da33f00 (ignoring)
01-03 14:00:53.116 658-22045/? D/audio_hw_primary: disable_audio_route: usecase(1) reset and update mixer path: low-latency-playback speaker
01-03 14:00:53.154 14820-14836/? E/Unity: AndroidJavaException: java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "instance" in class "Lcom/test/camerapreview/NativeCamera;" or its superclasses
                                          java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "instance" in class "Lcom/test/camerapreview/NativeCamera;" or its superclasses
                                              at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
                                              at com.unity3d.player.UnityPlayer.c(Unknown Source:0)
                                              at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source:151)
                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                              at android.os.Looper.loop(Looper.java:164)
                                              at com.unity3d.player.UnityPlayer$c.run(Unknown Source:20)
                                            at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0 
                                            at UnityEngine.AndroidJNISafe.GetStaticFieldID (IntPtr clazz, System.String name, System.String sig) [0x00000] in <filename unknown>:0 
                                            at UnityEngine._AndroidJNIHelper.GetFieldID (IntPtr jclass, System.String fieldName, System.String signature, Boolean isStatic) [0x00000] in <filena

它抱怨称为实例的变量,它是在从Unity调用的Setup函数中设置的。没有这个变量,我的插件就可以了。有了它,它崩溃了。

我也对build.gradle文件进行了更改。在这里。

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.google.android.gms:play-services-vision:9.4.0+' // I added this line.
    provided files('./libs/UnityPlayer.jar')
    compile files('libs/gson-2.8.2.jar')
}

android.libraryVariants.all { variant ->
    // Task names.
    String variantName = "${variant.name.capitalize()}"; // Like 'Debug'
    String deployTaskGroup = "plugin";
    String deployTaskName = "deploy${variantName}PluginArchive"; // Like 'deployDebugPluginArchive'
    String dependencyTaskName = "assemble${variantName}"; // Like 'assembleDebug'
    // Source.
    String sourceAARFolder = "${buildDir.getPath()}/outputs/aar/";
    String sourceAARName = "${project.name}-${variant.name}.aar";
    // Target.
    String targetAARFolder = "../../../Assets/Plugins/Android"; // Navigate into 'Assets'
    String targetAARName = "Native Camera.aar"; // The form you ship your plugin
    // Create task.
    task(deployTaskName, dependsOn: dependencyTaskName, type: Copy) {
        from(sourceAARFolder)
        into(targetAARFolder)
        include(sourceAARName)
        rename(sourceAARName, targetAARName)
    }.group = deployTaskGroup;
}

我添加了

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

更新

我已经尝试将变量从实例复制到mInstance并且我有相同的issuue。然后我尝试在函数内创建变量并返回它。现在我有一个更直观的错误日志,我不知道如何修复。

01-03 14:38:32.505 19629-19646/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/vision/face/FaceDetector;
                                          java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/vision/face/FaceDetector;
                                              at java.lang.reflect.Executable.getMethodReturnTypeInternal(Native Method)
                                              at java.lang.reflect.Method.getReturnType(Method.java:141)
                                              at java.lang.Class.getDeclaredMethods(Class.java:1880)
                                              at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:63)
                                              at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
                                              at com.unity3d.player.UnityPlayer.c(Unknown Source:0)
                                              at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source:151)
                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                              at android.os.Looper.loop(Looper.java:164)
                                              at com.unity3d.player.UnityPlayer$c.run(Unknown Source:20)
                                           Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.vision.face.FaceDetector" on path: DexPathList[[zip file "/data/app/com.tvgla.campreview-C0

由于 约翰劳里

1 个答案:

答案 0 :(得分:0)

但是,我遇到了同样的问题,这是由于我将自己的自定义库和Gson代码作为 .aar 包含在一个android应用程序项目中。并且由于.aar文件不会传播依赖项transitively,我在应用程序项目中遇到Gson类错误,在应用程序项目中导入gson解决了该问题!

Proguard :如果您使用Proguard混淆代码,请确保为gson添加了正确的规则,here