1

Possible Duplicate:
How do I load my own Java class in C on Android?
Application works in debug / run from Eclipse, but .APK gives .classNotFoundException when parsing XML layout that contains a custom View

In Android, I am accessing a native C library, by doing:

System.loadLibrary("testlib");

To load a native library. In the JNI_OnLoad() function, it is trying to find a Java glue code class:

JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
        JNIEnv *env;
        jclass k;
        jint r;

        r = vm->GetEnv ((void **) &env, JNI_VERSION_1_4);
        k = env->FindClass ("com/test/android/aclass");

The FindClass() fails, and throws a NoClassDefFoundError exception. Any idea why I cannot see my Java class from my C code?

I use this same library in another test application, and it works (so I am confident that the library works). I don't see why one app can find the java class, while the other cannot.

Community
  • 1
  • 1
bubba
  • 263
  • 1
  • 5
  • 13
  • Where is the `com/test/android/aclass` class defined? In the project itself or in a jar file that is mixed in? – Femi Apr 18 '12 at 05:43
  • Good article -- thanks for the link. But in the end found my problem was proguard.cfg. When I disabled proguard its now working. – bubba Apr 20 '12 at 02:31

1 Answers1

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