Если ваш пакет com.example.hellojni
, он захватывает поля DEBUG
и BUILD_TYPE
stati c из класса BuildConfig
:
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz )
{
jclass cls_HelloJni = env->FindClass("com/example/hellojni/BuildConfig");
jfieldID fid_HelloJNI_buildType = env->GetStaticFieldID(cls_HelloJni, "BUILD_TYPE", "Ljava/lang/String;");
jfieldID fid_HelloJNI_debug = env->GetStaticFieldID(cls_HelloJni, "DEBUG", "Z");
jstring jBuildType = (jstring) env->GetStaticObjectField(cls_HelloJni, fid_HelloJNI_buildType);
jboolean jDebug = env->GetStaticBooleanField(cls_HelloJni,fid_HelloJNI_debug);
const char * buildType = env->GetStringUTFChars(jBuildType, nullptr);
std::string out = (std::stringstream() << "Build type is " << buildType << ", debug says " << (jDebug ? "debug" : "not debug")).str();
env->ReleaseStringUTFChars(jBuildType, buildType);
return (env)->NewStringUTF(out.c_str());
}