无法在 Android Studio 中添加 *.so 库。JniLibs 目录不起作用



我为答案的答案进行了很多研究,但我什么也没找到。我无法在项目中添加.so库。

我将库放入/app/src/main/jnilibs/arm64-v8a中。该项目将得到反复,但执行后,以下错误会出现。

谢谢您的所有答案。

目录的结构在这里。ARMS64-V8A是我系统的正确文件夹。

build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.vtas_kassenterminal"
        minSdkVersion 27
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'org/apache/http/version.properties'
        exclude 'org/apache/http/nio/version.properties'
        exclude 'org/apache/http/client/version.properties'
        exclude 'org.apache.http.impl.nio.DefaultHttpServerIODispatch'
    }
    productFlavors {
    }
}
dependencies {
    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:design:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.squareup.okhttp3:okhttp:3.9.1'
    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 files('libs/acssmc-1.1.4.jar')
    implementation 'org.jetbrains:annotations-java5:15.0'
    implementation 'com.android.volley:volley:1.1.0'
}

日志:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.vtas_kassenterminal, PID: 10504
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.vtas_kassenterminal-zh4y12ECK4PCd-N-FXMp6A==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.vtas_kassenterminal-zh4y12ECK4PCd-N-FXMp6A==/lib/arm, /system/lib, /system/vendor/lib]]] couldn't find "libpcsclite.so"
        at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
        at java.lang.System.loadLibrary(System.java:1657)
        at com.example.vtas_kassenterminal.JacspcscLoader.<clinit>(JacspcscLoader.java:280)
        at com.example.vtas_kassenterminal.nfcTest.onCreate(nfcTest.java:135)
        at android.app.Activity.performCreate(Activity.java:7258)
        at android.app.Activity.performCreate(Activity.java:7249)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:7000)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

您必须在上面编写代码,以便gradle能够在项目的jnilibs文件夹上找到" .so"文件。

android {
sourceSets {
       main {         
            jniLibs.srcDirs = ['src/main/jnilibs']          
        }
    } 
}

,意思是 libpcsclite.so ARMS> ARMS64-V8A folde中找不到。尝试删除您的.so文件额外字符 .1.0.0 (我在图像中看到了(

如果上述解决方案不工作,请按照以下操作。

.so文件不仅在 ands 64-V8a 文件夹中工作。将.SO文件添加到 ARMEABI-V7A 目录中。文件夹名称取决于电话硬件(可能是处理器(。

和.so文件对于特定文件夹可能有所不同,例如 ands 64-V8a armeabi-v7a 等。通常最大的设备盖 ARMEABI-V7A

相关内容

  • 没有找到相关文章

最新更新