从本机代码访问生成的Android R类(Access generated Android R class from native code)
我想知道是否有一种方法可以从本机代码访问R类属性,我需要它来读取一些生成的ID,这些ID可能会在我每次执行项目的干净构建时发生变化,我宁愿不将它们手动传递给原生部分。
编辑正如@trashkalmar建议的那样解决方案:
static const char* const strClassName = "your/app/package/R$string"; clazz = env->FindClass(strClassName); if (clazz == NULL) { LOGE("Can't find class %s\n", strClassName); return result; } jfieldID field = env->GetStaticFieldID(clazz , "you_string_resource", "I"); jint value = env->GetStaticIntField(clazz, field);I'm wondering if there is a way to access R class attribute from native code, I need it to read some generated ID that may change every time i do a clean build of my project and I would prefer not to pass them manually to the native part.
EDIT As suggested from @trashkalmar here is the solution:
static const char* const strClassName = "your/app/package/R$string"; clazz = env->FindClass(strClassName); if (clazz == NULL) { LOGE("Can't find class %s\n", strClassName); return result; } jfieldID field = env->GetStaticFieldID(clazz , "you_string_resource", "I"); jint value = env->GetStaticIntField(clazz, field);最满意答案
访问您的R类并像其他任何类一样读取其字段。
Access your R class and read its fields as any other classes.
更多推荐
发布评论