jeudi 23 juillet 2020

Android app loading shared library from incorrect location

I am working on an Android app that is using a c++ shared library. Originally, the project works fine. I recently upgrade the Android Studio to version 4.0.1

When the code runs to the statement

try{
    System.loadLibrary("something");
} catch(Exception e) {...}

The application throws an exception

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "_ZN3Eld12PtrModelRefsEv" referenced by "/data/app/com.myapp-aXvdrU70cJvaDOn1c13zEQ==/lib/arm/libsomething.so"...

In the apk file, I can see the library binary file is located in apk/debug/app-armeabi-v7a-debug.apk/lib/armeabi-v7a/libsomething.so

It seems the app is trying to load the shared library from lib/arm instead of lib/armeabi-v7a

Under the folder something, I have the file build.gradle configs like:

android {
    defaultConfig{
        ndk {
            abiFilters "armeabi-v7a"
        }
    }
}

Using the readelf -A libsomething.so to check my library file attribute. I have the following result

Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "ARM v7"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv3
  Tag_Advanced_SIMD_arch: NEONv1
  Tag_ABI_PCS_GOT_use: GOT-indirect
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_enum_size: int
  Tag_CPU_unaligned_access: v6
  Tag_ABI_FP_16bit_format: IEEE 754

So, how can I let the function System.loadLibrary loading the binary library file from the correct location?

Aucun commentaire:

Enregistrer un commentaire