Android invoke own java code
#1
Sad 
Im a fresh developer. Thx to read this:
In XBMC for android, I add My own code(Java) ,it's package is org.xbmc.xbmc.Util
How C++ can invoke Util's function.
I try this In XBMCApp.cpp:
JNIEnv *env = NULL;
AttachCurrentThread(&env);
jclass UtilClass = NULL;
UtilClass = env->FindClass("org/xbmc/xbmc/Util");
CLog::Log(LOGDEBUG, "UtilClass is %d",UtilClass);

Unfortunately UtilClass is 0,so I can't callMethod in Util.

Any one has an idea? Thank you ~
Reply
#2
Please don't use org.xbmc.xbmc signature for your own packages. org.xbmc.xbmc.xxx is reserved for our usage.

Your code usage is stale

JNIEnv* env = xbmc_jnienv();
jclass UtilClass = env->FindClass("org/<your sig here>");
Reply
#3
Thx for your reply.
But it's still not working as what you said, I change my java class to com.star.Util
jclass stringClass = env->FindClass("java/lang/String");
CLog::Log(LOGDEBUG, "stringClass is %d",stringClass);

jclass UtilClass = env->FindClass("com/star/Util");
CLog::Log(LOGDEBUG, "bbbb UtilClass %d",UtilClass);

stringClass is OK, but UtilClass is 0, I also add Util java file in packing Makefile , Waiting for your opinion.
Reply
#4
JNIEnv* env = xbmc_jnienv(); <- you definitly did that?
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#5
(2013-07-11, 06:58)davilla Wrote: Please don't use org.xbmc.xbmc signature for your own packages. org.xbmc.xbmc.xxx is reserved for our usage.

Your code usage is stale

JNIEnv* env = xbmc_jnienv();
jclass UtilClass = env->FindClass("org/<your sig here>");

(2013-07-11, 11:03)Memphiz Wrote: JNIEnv* env = xbmc_jnienv(); <- you definitly did that?
I use xbmc frodo. what does xbmc_jnienv() mean?
the env init like this

int CXBMCApp::AttachCurrentThread(JNIEnv** p_env, void* thr_args /* = NULL */)
{
return m_activity->vm->AttachCurrentThread(p_env, thr_args);
}

Am I right ?, OR xbmc_jnienv() means other? thank you ~
Reply
#6
We are well past frodo in mainline. jni handling has been completely re-factored.

Perhaps you should push up to github the work you are doing so we can see all the code. Seeing two lines out of many lines of code will not give much help. Also perhaps you should pastebin the logcat of xbmc launching and trying to run your code. There could be lots of important messages there that we cannot see.
Reply
#7
OK,thank you, I'll try XBMC 13~ I'll back here next week.
Reply
#8
i try the latest XBMC(get code from Github.com/xbmc/xbmc) just now and still not work.
There are only 3 changes:
1.Add Util.java
package org.star.time;
public class Util {
public static int get(){
return 1;
}
}
2.Add 2 lines In XBMCApp.cpp for test
void CXBMCApp::SetSystemVolume(JNIEnv *env, float percent)
{
JNIEnv* envMy = xbmc_jnienv();
jclass UtilClass = envMy->FindClass("org/star/time/Util");
android_printf("UtilClass %d",UtilClass);
3.Add Util to Makefile (tools/android/packaging/Makefile)
@javac -classpath $(SDKROOT)/platforms/$(SDK_PLATFORM)/android.jar:xbmc/obj -d xbmc/obj -sourcepath xbmc/src xbmc/src/org/star/time/*.java

android_printf told me UtilClass is 0.What 's wrong u think~ Thanks again.
You can see these on https://github.com/usbwc/xbmc/
Reply
#9
The default classloader won't find your custom classes. You'll have to use an instance from the application. Something like:

Code:
#include "android/activity/XBMCApp.h"
#include "android/jni/ClassLoader.h"
jclass util = XBMCApp::getClassLoader().loadClass("org/star/time/Util");
Reply

Logout Mark Read Team Forum Stats Members Help
invoke own java code0