使用FIngerprintManager android API时出错

时间:2016-04-12 17:33:47

标签: java android classnotfoundexception android-fingerprint-api

我正在尝试在Android上使用新的指纹扫描功能。我从这里跟踪了谷歌的例子: https://github.com/googlesamples/android-FingerprintDialog

但是当我运行我的程序时,我收到了这个错误:

04-12 22:51:06.475 9218-9218/ivote.android.gj.ivote E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: ivote.android.gj.ivote, PID: 9218
                                                                      java.lang.NoClassDefFoundError: Failed resolution of: Landroid/hardware/fingerprint/FingerprintManager;
                                                                          at ivote.android.gj.ivote.ActivityPackage.HomeScreen.fingerScan(HomeScreen.java:233)
                                                                          at ivote.android.gj.ivote.ActivityPackage.HomeScreen$7.onResponse(HomeScreen.java:188)
                                                                          at ivote.android.gj.ivote.ActivityPackage.HomeScreen$7.onResponse(HomeScreen.java:176)
                                                                          at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
                                                                          at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
                                                                          at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
                                                                          at android.os.Handler.handleCallback(Handler.java:739)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                          at android.os.Looper.loop(Looper.java:135)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5383)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:939)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:734)
                                                                       Caused by: java.lang.ClassNotFoundException: Didn't find class "android.hardware.fingerprint.FingerprintManager" on path: DexPathList[[zip file "/data/app/ivote.android.gj.ivote-2/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
                                                                          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                          at ivote.android.gj.ivote.ActivityPackage.HomeScreen.fingerScan(HomeScreen.java:233) 
                                                                          at ivote.android.gj.ivote.ActivityPackage.HomeScreen$7.onResponse(HomeScreen.java:188) 
                                                                          at ivote.android.gj.ivote.ActivityPackage.HomeScreen$7.onResponse(HomeScreen.java:176) 
                                                                          at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60) 
                                                                          at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30) 
                                                                          at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) 
                                                                          at android.os.Handler.handleCallback(Handler.java:739) 
                                                                          at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                          at android.os.Looper.loop(Looper.java:135) 
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5383) 
                                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:939) 
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:734) 
                                                                        Suppressed: java.lang.ClassNotFoundException: android.hardware.fingerprint.FingerprintManager
                                                                          at java.lang.Class.classForName(Native Method)
                                                                          at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                                          at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                ... 15 more
                                                                       Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

我试图在谷歌上找到这个问题的解决方案,但它没有帮助。很少有问题指出错误的gradle文件,所以我的app gradle文件看起来像这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "ivote.android.gj.ivote"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    jcenter()
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile "com.android.support:support-v13:23.1.1"
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile project(path: ':volley')
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.github.PhilJay:MPAndroidChart:v2.2.3'
    compile 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
    compile 'com.google.zxing:core:3.2.0'
}

我试图解决这个错误一段时间,所以如果任何人可以帮助它将是很大的帮助。在此先感谢!

2 个答案:

答案 0 :(得分:0)

尝试减少正在使用的库的数量,或在应用程序中使用multidex。我希望你已达到65k方法计数限制。

答案 1 :(得分:0)

API 23 和更高版本支持

FingerprintManager。您应用的最低SDK支持是15 如果您的应用在Android版本早于Marshmellow的设备上运行,那么您需要使用FingerprintManagerCompat,否则您将遇到上述异常。

https://github.com/hiteshsahu/FingerPrint-Authentication-With-React-Native-Android/blob/master/android/app/src/main/java/com/aproject/modules/BiometricModule.java