Native shared library loaded in Android

I have a shared library housed in libs / armeabi folder. It loads with

System.loadLibrary("library_name.so");

      

The library is about 3MB in size. Loading times are very long. This sometimes lasts almost 20 seconds. It is blocking my GUI. I tried to put System.loadLibrary("library_name.so");

on another thread, but my GUI is still locked. I know that other applications use even larger .so files, but the load times are not that long. What could be the problem?

EDIT

3MB was the size of the debug version. The release version is about 800KB, but the problem is the same. Additional Information:

  • .so contains my two C ++ libraries that are linked in a circle
  • running arm-linux-androideabi-nm -D -C -g library_name.so

    displays many functions and variables
  • I don't use anymore LOCAL_WHOLE_STATIC_LIBRARIES

  • here is a table of section headers obtained with arm-linux-androideabi-readelf-tool

    :
Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al

  [ 0]                   NULL            00000000 000000 000000 00      0   0  0

  [ 1] .dynsym           DYNSYM          00000114 000114 00b400 10   A  2   1  4

  [ 2] .dynstr           STRTAB          0000b514 00b514 015b0c 00   A  0   0  1

  [ 3] .hash             HASH            00021020 021020 004d1c 04   A  1   0  4

  [ 4] .rel.dyn          REL             00025d3c 025d3c 006e98 08   A  1   0  4

  [ 5] .rel.plt          REL             0002cbd4 02cbd4 000468 08   A  1   6  4

  [ 6] .plt              PROGBITS        0002d03c 02d03c 0006b0 00  AX  0   0  4

  [ 7] .text             PROGBITS        0002d6f0 02d6f0 08e6e0 00  AX  0   0  8

  [ 8] .ARM.extab        PROGBITS        000bbdd0 0bbdd0 00bad0 00   A  0   0  4

  [ 9] .ARM.exidx        ARM_EXIDX       000c78a0 0c78a0 005b80 08  AL  7   0  4

  [10] .rodata           PROGBITS        000cd420 0cd420 005cc0 00   A  0   0  4

  [11] .data.rel.ro.loca PROGBITS        000d46d8 0d36d8 0006e4 00  WA  0   0  4

  [12] .fini_array       FINI_ARRAY      000d4dbc 0d3dbc 000008 00  WA  0   0  4

  [13] .init_array       INIT_ARRAY      000d4dc4 0d3dc4 00009c 00  WA  0   0  4

  [14] .data.rel.ro      PROGBITS        000d4e60 0d3e60 00384c 00  WA  0   0  8

  [15] .dynamic          DYNAMIC         000d86ac 0d76ac 000100 08  WA  2   0  4

  [16] .got              PROGBITS        000d87ac 0d77ac 000854 00  WA  0   0  4

  [17] .data             PROGBITS        000d9000 0d8000 000648 00  WA  0   0  8

  [18] .bss              NOBITS          000d9648 0d8648 047271 00  WA  0   0  8

  [19] .comment          PROGBITS        00000000 0d8648 000026 01  MS  0   0  1

  [20] .note.gnu.gold-ve NOTE            00000000 0d8670 00001c 00      0   0  4

  [21] .ARM.attributes   ARM_ATTRIBUTES  00000000 0d868c 00002d 00      0   0  1

  [22] .shstrtab         STRTAB          00000000 0d86b9 0000d8 00      0   0  1

      

+3


source to share


2 answers


The problem is static initialization in some constructor which takes a long time to complete



0


source


Try to reduce the number of exported functions in your shared library. you can use

arm-linux-androideabi-nm -D -C -g library_name.so

      

and check if the list is too long and remove the ones you don't use (declare them static). You can take a look at the manual nm

at $man nm

and read on how to use and interpret it.

If you have a lot of functions to use, use RegisterNatives () to register your functions instead of relying on name management and lookup - which is what you do when you specify your function names, for example Java_your_path_YourClass_yourFunction

.

You can also try strip

(arm-linux-androideabi-strip) your library if it has symbols.



To avoid blocking the UI, you can try loading your shared library earlier on a different thread and wait for it.

I would not use LOCAL_WHOLE_STATIC_LIBRARIES if exposing static libraries is not what I ultimately want.

LOCAL_WHOLE_STATIC_LIBRARIES

     
  •   
  • These are static libraries that you want to include in your module without letting the linker remove dead code from them.  
  • This is mostly useful when you want to add a static library to a shared library and get the contents of the static library from the shared library.  

Try to fix this issue instead of working with any build issue.

+1


source







All Articles