Reputation: 1013
I have a shared library placed in libs/armeabi folder. It is loaded using
System.loadLibrary("library_name.so");
The size of the library is around 3MB. The loading time is very long. It sometimes last almost 20 seconds. It blocks my GUI. I tried to put System.loadLibrary("library_name.so");
in a different thread but my GUI is still blocked. I know that others apps use even bigger .so files, but the loading time is not so big. What could be the problem?
EDIT
3MB was the size of the debug version. Release version is about 800KB, but the problem is the same. Some additional info:
arm-linux-androideabi-nm -D -C -g library_name.so
displays a lot of functions and variablesLOCAL_WHOLE_STATIC_LIBRARIES
anymorearm-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
Upvotes: 4
Views: 2443
Reputation: 1013
The problem is static initialization in some constructor which takes to much time to finishis
Upvotes: 1
Reputation: 28087
Try to reduce number of exported functions in your shared library. You can use
arm-linux-androideabi-nm -D -C -g library_name.so
and check if that list is unnecessarily long, and remove the ones that you don't use (declare them static). You can look up nm
's manual by $man nm
and read about how to use and interpret it.
If you need to use lots of functions, use RegisterNatives() to register your functions instead of relying on name mangling and lookup - that's what you do when you give your functions names like Java_your_path_YourClass_yourFunction
.
You can also try to strip
(arm-linux-androideabi-strip) your library, if it has symbols.
To avoid blocking UI, you can try to load your shared library early in a different thread and wait for it.
I wouldn't use LOCAL_WHOLE_STATIC_LIBRARIES, if exposing static libraries is not what I ultimately want.
LOCAL_WHOLE_STATIC_LIBRARIES
- These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them.
- This is mostly useful if you want to add a static library to a shared library and have the static library's content exposed from the shared library.
Try to fix that problem instead of working around some build problem.
Upvotes: 1