简体   繁体   English

从C ++调用Android调试方法

[英]Calling Android debug method from C++

I have spent a ridiculous amount of time trying to figure this out and I am at an absolute loss. 我花了很多荒谬的时间试图弄清楚这一点,但我绝对不知所措。

I am working with the JUCE library and have modified one of their sample projects. 我正在使用JUCE库,并且已经修改了他们的示例项目之一。 My goal is to have a very simple Android app that is written in C++ and then ported to Android. 我的目标是拥有一个非常简单的Android应用程序,该应用程序用C ++编写,然后移植到Android。 I need a function in C++ that I can call that will then call a function on the Android side that will return my heap size and other characteristics to my C++ code so that I can manage memory there. 我需要可以调用的C ++函数,然后再在Android端调用一个函数,该函数会将堆大小和其他特征返回给C ++代码,以便在那里管理内存。

If anyone has a simple solution that would be amazing. 如果有人有一个简单的解决方案,那就太好了。 Right now my current snag is this: 现在我当前的障碍是:

char const buf[] = "From JNI";

jstring jstr = env->NewStringUTF(buf);

jclass clazz = env->FindClass("android/os/Debug");

But I keep getting an error saying that 'NewStringUTF' is not a _JNIEnv member... but if I right click on the method and jump to the definition, I see it in my jni.h file... any suggestions? 但是我总是收到一个错误消息,说“ NewStringUTF”不是_JNIEnv成员...但是,如果我右键单击该方法并跳转到定​​义,我会在jni.h文件中看到它...有什么建议吗? I'm working in Xcode by the way... 我正在用Xcode工作...

Is it plain C, not C++? 它是纯C语言,不是C ++语言吗? Perhaps your file has a .c extension. 也许您的文件扩展名为.c。

If it's plain C it should be 如果是纯C,应该是

 JNIEnv* env;

 JNI_CreateJavaVM(&jvm, (void **)&env, &args);

 (*env)->NewStringUTF(env, buf);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM