I'm writing a native app with a Java class derived from NativeActivity. I need to get a reference to that class in my C++ code, but when I try to do that in code called from ANativeActivity_onCreate the class can't be found. My code looks something like:
void ANativeActivity_onCreate(ANativeActivity *activity,
void *savedState, size_t savedStateSize)
{
...
JNIEnv *jenv = activity->env;
dsActivityClass = jenv->FindClass("uk/co/realh/hgame/HGameActivity");
if (!dsActivityClass)
{
// Log error and return to Java
}
...
}
My logcat shows the error printed by the if clause followed by a report of a java.lang.NoClassDefFoundError.
I've double-checked the class name, I'm sure it's correct. And the class has to have been instantiated by the time the above code is called because it includes a static code block to load gnustl_shared, without which Android can't load my main library containing ANativeActivity_onCreate
. What could cause the class to not be found? It's defined like this:
package uk.co.realh.hgame;
import android.app.NativeActivity;
...
public class HGameActivity extends NativeActivity {
...
}