# HG changeset patch # User John Tsiombikas # Date 1431644786 -10800 # Node ID cf5964db7ff302ca6b07a8e5d73f8cf546a1e722 # Parent 7eb73ce46dd022f177a4482e0180ed4b90601a7c finally jni calls fucking work diff -r 7eb73ce46dd0 -r cf5964db7ff3 .clang_complete --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.clang_complete Fri May 15 02:06:26 2015 +0300 @@ -0,0 +1,3 @@ +-Isrc +-Isrc/android +-I$NDK/platforms/android-21/arch-arm/usr/include diff -r 7eb73ce46dd0 -r cf5964db7ff3 android/Makefile --- a/android/Makefile Thu May 14 23:46:56 2015 +0300 +++ b/android/Makefile Fri May 15 02:06:26 2015 +0300 @@ -8,6 +8,7 @@ # ------------------------ src += $(wildcard $(root)/src/android/*.c) +jsrc = $(wildcard $(root)/src/android/*.java) obj = $(src:.c=.o) $(ccsrc:.cc=.o) lib = libs/armeabi/lib$(name).so @@ -34,10 +35,10 @@ .PHONY: release release: $(apk-release) -$(apk-debug): $(lib) AndroidManifest.xml +$(apk-debug): $(lib) $(jsrc) AndroidManifest.xml ant debug -$(apk-release): $(lib) AndroidManifest.xml +$(apk-release): $(lib) $(jsrc) AndroidManifest.xml ant release .PHONY: lib diff -r 7eb73ce46dd0 -r cf5964db7ff3 src/android/MainActivity.java --- a/src/android/MainActivity.java Thu May 14 23:46:56 2015 +0300 +++ b/src/android/MainActivity.java Fri May 15 02:06:26 2015 +0300 @@ -4,8 +4,9 @@ import android.util.Log; public class MainActivity extends NativeActivity { - public static void foo(String s, int n) + public static int foo(String s, int n) { - Log.i("3DPS", s + ": " + n); + Log.i("photoshoot3d", s + ": " + n); + return 42; } } diff -r 7eb73ce46dd0 -r cf5964db7ff3 src/android/amain.c --- a/src/android/amain.c Thu May 14 23:46:56 2015 +0300 +++ b/src/android/amain.c Fri May 15 02:06:26 2015 +0300 @@ -32,7 +32,9 @@ jstring jstr; int res; - if(!(foo_id = (*jni)->GetStaticMethodID(jni, activity_class, "foo", "(Ljava/lang/String;I)V"))) { + printf("call_foo() [activity_class=%p]\n", (void*)activity_class); + + if(!(foo_id = (*jni)->GetStaticMethodID(jni, activity_class, "foo", "(Ljava/lang/String;I)I"))) { fprintf(stderr, "static method foo not found\n"); return -1; } @@ -59,7 +61,7 @@ fprintf(stderr, "failed to attach native thread to Java VM\n"); exit(1); } - activity_class = app->activity_class; + activity_class = (*jni)->GetObjectClass(jni, app->activity->clazz); printf("JNI call returned: %d\n", call_foo("testing C->java jni calls", 42)); @@ -288,3 +290,10 @@ dpy = 0; } + +/* +static jclass get_java_class(const char *name) +{ + jobject native +} +*/ diff -r 7eb73ce46dd0 -r cf5964db7ff3 src/android/native_glue.c --- a/src/android/native_glue.c Thu May 14 23:46:56 2015 +0300 +++ b/src/android/native_glue.c Fri May 15 02:06:26 2015 +0300 @@ -37,6 +37,36 @@ # define LOGV(...) ((void)0) #endif +/* +jint JNI_OnLoad(JavaVM *jvm, void *unused) +{ + JNIEnv *jni; + jclass act_cls_local; + + LOGI("OnLoad called ! <------------------\n"); + + if((*jvm)->GetEnv(jvm, (void**)&jni, JNI_VERSION_1_6) != JNI_OK) { + LOGE("OnLoad: failed to get JNIEnv from VM\n"); + return -1; + } + + jclass foo = (*jni)->FindClass(jni, "java/lang/String"); + if(!foo) { + LOGE("String class not found!!!!!!\n"); + } else { + LOGE("Found String class!!!!!!\n"); + } + + if(!(act_cls_local = (*jni)->FindClass(jni, ACTIVITY_NAME))) { + LOGE("could not find activity: " ACTIVITY_NAME); + return 0; + } + activity_class = (*jni)->NewGlobalRef(jni, act_cls_local); + + return JNI_VERSION_1_6; +} +*/ + static void free_saved_state(struct android_app* android_app) { pthread_mutex_lock(&android_app->mutex); if (android_app->savedState != NULL) { @@ -180,6 +210,7 @@ AInputQueue_detachLooper(android_app->inputQueue); } AConfiguration_delete(android_app->config); + android_app->destroyed = 1; pthread_cond_broadcast(&android_app->cond); pthread_mutex_unlock(&android_app->mutex); @@ -243,25 +274,10 @@ static struct android_app* android_app_create(ANativeActivity* activity, void* savedState, size_t savedStateSize) { - JNIEnv *jni = activity->env; struct android_app* android_app = malloc(sizeof(struct android_app)); memset(android_app, 0, sizeof(struct android_app)); android_app->activity = activity; - { - jclass foo = (*jni)->FindClass(jni, "java/lang/String"); - if(!foo) { - LOGE("String class not found!!!!!!\n"); - } else { - LOGE("Found String class!!!!!!\n"); - } - } - - if(!(android_app->activity_class = (*jni)->FindClass(jni, ACTIVITY_NAME))) { - LOGE("could not find activity: " ACTIVITY_NAME); - return 0; - } - pthread_mutex_init(&android_app->mutex, NULL); pthread_cond_init(&android_app->cond, NULL); diff -r 7eb73ce46dd0 -r cf5964db7ff3 src/android/native_glue.h --- a/src/android/native_glue.h Thu May 14 23:46:56 2015 +0300 +++ b/src/android/native_glue.h Fri May 15 02:06:26 2015 +0300 @@ -182,9 +182,6 @@ AInputQueue* pendingInputQueue; ANativeWindow* pendingWindow; ARect pendingContentRect; - - // MainActivity class - jclass activity_class; }; enum {