2

Possible Duplicate:
Application works in debug / run from Eclipse, but .APK gives .classNotFoundException when parsing XML layout that contains a custom View

I am re-using an existing NDK compiled library from another application.

When I try to load the library using System.loadLibrary(), it crashes with SIGSEGV.

Simply, I am doing this:

  static {
        System.loadLibrary("testlib");
      }

I am confident the library is good, as it is being used in another application (without modification). I can also load other libraries this way without any issue.

I am pretty new to using Android/NDK -- is there something I need to be careful to specify or setup that maybe I missed?

Here is what I am seeing in the log:

04-17 09:33:37.725  6100  6100 D dalvikvm: Trying to load lib /data/data/com.test.android/lib/libtestlib.so 0x4051617
0
04-17 09:33:37.733  6100  6100 D dalvikvm: Added shared lib /data/data/com.test.android/lib/libtestlib.so 0x40516170
04-17 09:33:37.733  6108  6108 I DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
04-17 09:33:37.733  6108  6108 I DEBUG   : Build fingerprint: 'verizon/venus2_vzw/cdma_venus2:2.3.4/4.5.1-110-VNS-35/120113:user/release-keys'
04-17 09:33:37.733  6108  6108 I DEBUG   : pid: 6100, tid: 6100  >>> com.test.android <<<
04-17 09:33:37.733  6108  6108 I DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000018
04-17 09:33:37.733  6108  6108 I DEBUG   :  r0 00000005  r1 aca83d13  r2 000415a6  r3 81db5c4c
04-17 09:33:37.733  6108  6108 I DEBUG   :  r4 00000000  r5 00000000  r6 81db5c4c  r7 81db5c40
04-17 09:33:37.733  6108  6108 I DEBUG   :  r8 0000cec8  r9 81c8734d  10 002b1284  fp 00000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  ip fffffe8c  sp bef91e48  lr aca6661b  pc aca45c0e  cpsr 20000070
04-17 09:33:37.733  6108  6108 I DEBUG   :  d0  643a64696f72646e  d1  6472656767756265
04-17 09:33:37.733  6108  6108 I DEBUG   :  d2  81dbd63081dc20c8  d3  81dc30a081c84481
04-17 09:33:37.733  6108  6108 I DEBUG   :  d4  81c844b981db6ccc  d5  81dc20b481dc209c
04-17 09:33:37.733  6108  6108 I DEBUG   :  d6  81dc20cc81c844ad  d7  81c844a181dbb618
04-17 09:33:37.733  6108  6108 I DEBUG   :  d8  0000000000000000  d9  0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d10 0000000000000000  d11 0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d12 0000000000000000  d13 0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d14 0000000000000000  d15 0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d16 bef91b68405515a8  d17 0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d18 0707070703030303  d19 0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d20 0100010001000100  d21 0100010001000100
04-17 09:33:37.733  6108  6108 I DEBUG   :  d22 0000000000000000  d23 0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d24 0000000000000000  d25 0000000000000000
04-17 09:33:37.733  6108  6108 I DEBUG   :  d26 0100010001000100  d27 0100010001000100
04-17 09:33:37.733  6108  6108 I DEBUG   :  d28 0100010001000100  d29 0100010001000100
04-17 09:33:37.733  6108  6108 I DEBUG   :  d30 00c7000000c10000  d31 00d3000000cd0000
04-17 09:33:37.733  6108  6108 I DEBUG   :  scr 20000012

If I run this on the emulator, it works fine.

Community
  • 1
  • 1
bubba
  • 263
  • 1
  • 5
  • 13

2 Answers2

1
System.loadLibrary() loads library from current project and System.load(fullPathLibName) load library from specific path.

So, use System.load().

Suvam Roy
  • 1,282
  • 2
  • 11
  • 21
  • Thanks for the suggestion, but its not having any problem finding the library. Its crashing with SEGV on loading the library. – bubba Apr 17 '12 at 13:32
  • Added some more in the description above to show its finding and loading the library. – bubba Apr 17 '12 at 13:38
  • Use the implemented native method class with its package name of that application which is working fine. I think the native method is unable to link with native library. – Suvam Roy Apr 17 '12 at 18:11
  • Got a little further. Found that the problem is occurring in the JNI_OnLoad() of the native code. It is trying to do a env->FindClass("com/test/android/aclass"). Its not finding the class, getting NULL, and later trying to deference the NULL pointer. OK, that explains the SEGV. But why can I not FindClass in the JNI_OnLoad? It is throwing NoClassDefFoundError exception. Any ideas? – bubba Apr 18 '12 at 04:56
  • JNI_OnLoad() is used in jni to register your native methods for C++ compiler. At first look at all native methods which are registered in JNI_OnLoad(), should be the same function name with proper arguments and proper return type in java class file. If the native is declared as env->FindClass("com/test/android/aclass"), that means you have to declare all native method in aclass.java under com/test/android otherwise jni can't link with java class. – Suvam Roy Apr 18 '12 at 05:44
  • Yes, that is how it is. However, the FindClass() is failing, before the methods are registered (it needs to find the class in order to register the methods). Any clue why it can't find the java class? – bubba Apr 18 '12 at 06:00
  • What's your java class name package name? – Suvam Roy Apr 18 '12 at 06:03
  • post your cpp code where the methods are being registered. – Suvam Roy Apr 18 '12 at 11:25
  • Thanks for all your help Suvam... but I've finally tracked this down to a proguard issue. – bubba Apr 20 '12 at 02:35
0

Found the answer.
My clue was that it would run fine if I ran it through eclipse, and only had this problem when I created a .apk file.

I found the solution here: Application works in debug / run from Eclipse, but .APK gives .classNotFoundException when parsing XML layout that contains a custom View

Community
  • 1
  • 1
bubba
  • 263
  • 1
  • 5
  • 13