从本机代码访问生成的Android R类(Access generated Android R class from native code)

编程入门 行业动态 更新时间:2024-10-12 03:19:27
本机代码访问生成的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.

更多推荐

本文发布于:2023-07-17 14:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1145625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:本机   代码   Android   Access   code

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!