J'ai un problème similaire à this question, mais légèrement différent. J'ai compilé une bibliothèque .so à utiliser avec JNI. Parce qu'il est grand (15 Mo), je le place sur la carte SD au lieu de l'utiliser dans l'application standard.Android - échec lors du chargement de la bibliothèque
Le fichier est appelé libSample.so et il est situé à /data/library/libSample.so
je charge dans un bloc d'initialisation statique:
try {
File sdcard = Environment.getExternalStorageDirectory();
File libraryLoc = new File(sdcard.getAbsolutePath() + "/library/libSample.so");
Log.i("Library", "Does the library exist?" + libraryLoc.exists());
System.load(libraryLoc.getAbsolutePath());
}
catch (UnsatisfiedLinkError e) {
Log.e("Translator", e.getMessage());
Log.e("Translator", e.toString());
}
est ici la sortie logcat pertinente:
09-02 16:42:58.882: DEBUG/dalvikvm(4185): Trying to load lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x434fb6f8
09-02 16:42:58.892: DEBUG/dalvikvm(4185): Added shared lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x434fb6f8
09-02 16:42:58.892: DEBUG/dalvikvm(4185): No JNI_OnLoad found in /data/data/com.example.hellojni/lib/libhello-jni.so 0x434fb6f8
09-02 16:42:58.892: INFO/Library(4185): Library exists: true
09-02 16:42:58.902: INFO/Library(4185): Library can be read: true
09-02 16:42:58.902: DEBUG/dalvikvm(4185): Trying to load lib /sdcard/library/libSample.so 0x434fb6f8
09-02 16:42:58.902: INFO/dalvikvm(4185): Unable to dlopen(/sdcard/library/libSample.so): Cannot find library
09-02 16:42:58.912: ERROR/Translator(4185): Library /sdcard/library/libSample.so not found
09-02 16:42:58.912: ERROR/Translator(4185): java.lang.UnsatisfiedLinkError: Library /sdcard/library/libSample.so not found
Tous idée quel est le problème? J'ai lu le post à propos de can android load dll's from sdcard in native mode qui disait que la carte SD ne peut pas être utilisée pour charger les bibliothèques, alors j'ai déplacé le .so dans /data/data/com.example.hellojni/lib/libSample.so (les données de l'application privée emplacement de stockage). Aucun changement:
09-02 16:53:18.332: DEBUG/dalvikvm(4515): Trying to load lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x434fb6f8
09-02 16:53:18.342: DEBUG/dalvikvm(4515): Added shared lib /data/data/com.example.hellojni/lib/libhello-jni.so 0x434fb6f8
09-02 16:53:18.342: DEBUG/dalvikvm(4515): No JNI_OnLoad found in /data/data/com.example.hellojni/lib/libhello-jni.so 0x434fb6f8
09-02 16:53:18.352: INFO/Library(4515): Library exists: true
09-02 16:53:18.352: INFO/Library(4515): Library can be read: true
09-02 16:53:18.352: DEBUG/dalvikvm(4515): Trying to load lib /data/data/com.example.hellojni/lib/libSample.so 0x434fb6f8
09-02 16:53:18.482: INFO/dalvikvm(4515): Unable to dlopen(/data/data/com.example.hellojni/lib/libSample.so): Cannot find library
09-02 16:53:18.492: ERROR/Translator(4515): Library /data/data/com.example.hellojni/lib/libSample.so not found
09-02 16:53:18.492: ERROR/Translator(4515): java.lang.UnsatisfiedLinkError: Library /data/data/com.example.hellojni/lib/libSample.so not found
Ce que je ne comprends pas que la bibliothèque existe bien, et le système d'exploitation tente de le charger ... donc ce qui en ferait échouer? Suite à l'avis de l'un des commentateurs, j'ai essayé d'attacher via strace pour obtenir des informations d'erreur plus détaillées. Le journal peut être trouvé comme github gist.
L'erreur semble être sur les lignes 47-51:
mprotect(0x4235d000, 4096, PROT_READ) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbeb58080) = -1 ENOTTY (Not a typewriter)
write(1, "bionic/linker/linker.c:1243| ERROR: 34 unknown reloc type 3 @ 0x811a854c (2441)\n", 83) = 83
write(1, "bionic/linker/linker.c:1641| ERROR: failed to link /data/data/com.example.hellojni/lib/libSample.so\n", 100) = 100
munmap(0x81000000, 8839168) = 0
Voici le readelf de la bibliothèque:
arm-eabi-readelf -d libSample.so
Dynamic section at offset 0x80b648 contains 17 entries:
Tag Type Name/Value
0x00000019 (INIT_ARRAY) 0x7ff234
0x0000001b (INIT_ARRAYSZ) 76 (bytes)
0x00000004 (HASH) 0xd4
0x00000005 (STRTAB) 0x7f41c
0x00000006 (SYMTAB) 0x2650c
0x0000000a (STRSZ) 1197287 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000003 (PLTGOT) 0x80c6f0
0x00000002 (PLTRELSZ) 76480 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x1ccb84
0x00000011 (REL) 0x1a3904
0x00000012 (RELSZ) 168576 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x00000016 (TEXTREL) 0x0
0x6ffffffa (RELCOUNT) 2412
0x00000000 (NULL) 0x0
J'ai essayé à la fois avec loadLibrary et charge – I82Much
Quelle version d'Android que vous utilisez? Les versions plus récentes sont un peu plus détaillées sur les échecs dlopen(). Les anciennes versions de l'éditeur de liens dynamiques ont indiqué "non trouvé" pour tout. Une chose qui aide parfois est de mettre en place un programme de ligne de commande trivial en C qui ne fait qu'appeler dlopen() sur votre lib et rendre compte du résultat. Si cela échoue, vous savez que c'est un problème de lib. s'il réussit, le problème est ailleurs. – fadden
Comment compilez-vous un tel programme avec le compilateur croisé android? Je ne sais pas où trouver les symboles non résolus dlopen, dlerror, etc. bras eabi nm -u libTester.exe U __aeabi_unwind_cpp_pr1 U __gxx_personality_v0 U __sF U dlclose U dlerror U dlopen U dlsym U fprintf – I82Much