4

I researched a lot for an answer of my question, but I didn't find anything. I can't add the .so library in my project.

I put the library in /app/src/main/jniLibs/arm64-v8a. The project will complile but on execution the following error comes.

Thank you for all answers.

Structure of directorys is here. arms64-v8a is the correct folder for my System.

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'
}

Log:

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)
Taimoor Suleman
  • 1,588
  • 14
  • 29
Taylan Kaya
  • 41
  • 1
  • 4

2 Answers2

2

you should have to write above code so that gradle can able to find out ".so" files on your project's jniLibs Folder.

android {
sourceSets {
       main {         
            jniLibs.srcDirs = ['src/main/jnilibs']          
        }
    } 
}
Maulik Baraiya
  • 203
  • 3
  • 9
  • `src/main/jniLibs` is the default search location, see https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs – DarkNeuron Jan 09 '23 at 13:51
0

That means libpcsclite.so not find in arms64-v8a folde. Try to remove your .so file extra character .1.0.0 (I saw this in image)

If above solution not work follow the below.

The .so file not only work in arms64-v8a folder. Add your .so file in armeabi-v7a directory. The folder name depend on Phone Hardware (May be processor).

And .so file May be different for specific folder like arms64-v8a or armeabi-v7a and so on. Generally maximum device cover armeabi-v7a.

Tariqul Islam
  • 680
  • 6
  • 14
  • Thank you I came a step forward, but now it says: java.lang.UnsatisfiedLinkError: dlopen failed: library "libdl.so.2" not found but I don't want to add this library. I only say: static { System.loadLibrary("pcsclite"); } – Taylan Kaya Jul 05 '19 at 12:17
  • Are you sure that libpcsclite has no dependency on libdl.so? .so file contains some method or function and it may be depend on other .so file – Tariqul Islam Jul 05 '19 at 12:20
  • Where I should add the libdl.so? Also in arms64-v8a directory? – Taylan Kaya Jul 05 '19 at 12:22
  • All .so file will be in the same directory. **Note:** single .so file has several directory type. that i mentioned in my answer. – Tariqul Islam Jul 05 '19 at 12:24
  • Welcome :) I think you got basic idea. – Tariqul Islam Jul 05 '19 at 12:28