如何解决Android中“找不到libjnisgfplib.so”错误

时间:2019-03-29 07:52:16

标签: android android-ndk android-gradle android-library android-build

我正在开发使用Secure-Gen Fingerprint SDK的Android应用程序。为此,我使用了 jniLibs ,该应用还具有加密解密功能,因此我使用了 CMake native-lib.cpp 文件中保存一些密码。

当我不使用CMake时,一切正常,但是将两者一起使用会在使用指纹SDK的屏幕上引发异常。

下面是异常的堆栈跟踪:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/app.mypackagename.debug-2/base.apk", zip file "/data/app/app.mypackagename.debug-2/split_lib_slice_0_apk.apk"],nativeLibraryDirectories=[/data/app/app.mypackagename.debug-2/lib/arm, /data/app/app.mypackagename.debug-2/base.apk!/lib/armeabi-v7a, /data/app/app.mypackagename.debug-2/split_lib_slice_0_apk.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /system/vendor/lib, /product/lib]]] couldn't find "libjnisgfplib.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:989)
        at java.lang.System.loadLibrary(System.java:1533)
        at SecuGen.FDxSDKPro.JSGFPLib.<clinit>(JSGFPLib.java:196)
        at app.mypackagename.modules.home.fragments.VerifyBiometricFragment.onCreateView(VerifyBiometricFragment.java:114)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
        at android.os.Handler.handleCallback(Handler.java:761)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6617)
        at java.lang.reflect.Method.invoke(Native Method)

下面是build.gradle文件部分

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "app.mypackagename"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        flavorDimensions 'default'
        multiDexEnabled true

        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }
    buildTypes {
        release {
            multiDexKeepFile file('multidex-config.txt')
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true
            applicationIdSuffix ".debug"
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
    productFlavors {
        MyProductFlavor {

        }
    }
    sourceSets {
        main {
            java {
                srcDirs('src/MyProductFlavor/java/src', 'src/main/java/src')
            }
            res {
                srcDirs('src/MyProductFlavor/res/src', 'src/main/res/src')
            }
        }
        MyProductFlavor {
            java {
                srcDirs('src/MyProductFlavor/java/src', 'src/main/java/src')
            }
            res {
                srcDirs('src/MyProductFlavor/res/src', 'src/main/res/src')
            }
        }


    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    /* Android Default*/
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:support-v4:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'

    implementation files('libs/FDxSDKProAndroid.jar')
}

下面是我的应用程序体系结构的屏幕截图:

enter image description here

我尝试使用以下方法

  • 尝试在abiFilter中添加带有build.gradle的NDK块。
  • 尝试添加 build.gragle文件中的以下代码段
    android {
        splits {
            abi {
                enable true
                reset()
                include 'armeabi-v7a'
            }
        }
    }
  • 试图在android.useDeprecatedNdk=true中添加gradle.properties

以上方法都没有为我工作,但仍然存在异常。

我已经通过分析APK 进行了检查,结果显示这些.so文件已打包。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试以下步骤:

1)将所有jniLibs(arm64-v8a,armeabi,x86)文件粘贴到 libs 目录中。

2)在基于应用的gradle文件中编写代码

splits {
    abi {
        enable true
        reset()
        include 'x86', 'armeabi', 'x86_64', 'arm64-v8a'
        universalApk true
    }
}
sourceSets {
    main {
        jniLibs.srcDirs = ["libs"]
    }
}

3)将此行添加到您的依赖项中:

implementation fileTree(include: ['*.jar','*.so'], dir: 'libs')