Android JNI DefineClass等效(加载类)

huangapple go评论60阅读模式
英文:

Android JNI DefineClass Equivelent (Loading Classes)

问题

I am in JNI code, and I have a .class file, which I want to dynamically load and use as a jclass. This is normally done by calling env->DefineClass(...), but that appears to be removed in the Android JNI, as it prompts me with:

JNI DefineClass is not supported

Which makes sense based on the implementation: https://android.googlesource.com/platform/art/+/master/runtime/jni/jni_internal.cc#665

I don't see anything online discussing how to actually get this functionality from the JNI, though. What mechanism can I use to dynamically load Java classes from the JNI?

英文:

I am in JNI code, and I have a .class file, which I want to dynamically load and use as a jclass. This is normally done by calling env->DefineClass(...) but that appears to be removed in the Android JNI, as it prompts me with:

JNI DefineClass is not supported

Which makes sense based on the implementation: https://android.googlesource.com/platform/art/+/master/runtime/jni/jni_internal.cc#665

I don't see anything online discussing how to actually get this functionality from the JNI, though. What mechanism can I use to dynamically load Java classes from the JNI?

答案1

得分: 1

这是根本不可能的。
Android应用程序的编译过程将Java .class文件转换为一种称为“DEX”的格式,该格式嵌入到APK中。

没有用于加载额外DEX文件的运行时功能。

英文:

This is fundamentally impossible.
The compilation process for Android applications turns Java .class files into a format called "DEX", which is baked into the APK.

There is no runtime functionality for loading additional DEX files.

huangapple
  • 本文由 发表于 2023年6月6日 09:52:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76410955.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定