3dphotoshoot

changeset 2:cf5964db7ff3

finally jni calls fucking work
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 15 May 2015 02:06:26 +0300
parents 7eb73ce46dd0
children 9df99687a2ff
files .clang_complete android/Makefile src/android/MainActivity.java src/android/amain.c src/android/native_glue.c src/android/native_glue.h
diffstat 6 files changed, 51 insertions(+), 24 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.clang_complete	Fri May 15 02:06:26 2015 +0300
     1.3 @@ -0,0 +1,3 @@
     1.4 +-Isrc
     1.5 +-Isrc/android
     1.6 +-I$NDK/platforms/android-21/arch-arm/usr/include
     2.1 --- a/android/Makefile	Thu May 14 23:46:56 2015 +0300
     2.2 +++ b/android/Makefile	Fri May 15 02:06:26 2015 +0300
     2.3 @@ -8,6 +8,7 @@
     2.4  # ------------------------
     2.5  
     2.6  src += $(wildcard $(root)/src/android/*.c)
     2.7 +jsrc = $(wildcard $(root)/src/android/*.java)
     2.8  
     2.9  obj = $(src:.c=.o) $(ccsrc:.cc=.o)
    2.10  lib = libs/armeabi/lib$(name).so
    2.11 @@ -34,10 +35,10 @@
    2.12  .PHONY: release
    2.13  release: $(apk-release)
    2.14  
    2.15 -$(apk-debug): $(lib) AndroidManifest.xml
    2.16 +$(apk-debug): $(lib) $(jsrc) AndroidManifest.xml
    2.17  	ant debug
    2.18  
    2.19 -$(apk-release): $(lib) AndroidManifest.xml
    2.20 +$(apk-release): $(lib) $(jsrc) AndroidManifest.xml
    2.21  	ant release
    2.22  
    2.23  .PHONY: lib
     3.1 --- a/src/android/MainActivity.java	Thu May 14 23:46:56 2015 +0300
     3.2 +++ b/src/android/MainActivity.java	Fri May 15 02:06:26 2015 +0300
     3.3 @@ -4,8 +4,9 @@
     3.4  import android.util.Log;
     3.5  
     3.6  public class MainActivity extends NativeActivity {
     3.7 -	public static void foo(String s, int n)
     3.8 +	public static int foo(String s, int n)
     3.9  	{
    3.10 -		Log.i("3DPS", s + ": " + n);
    3.11 +		Log.i("photoshoot3d", s + ": " + n);
    3.12 +		return 42;
    3.13  	}
    3.14  }
     4.1 --- a/src/android/amain.c	Thu May 14 23:46:56 2015 +0300
     4.2 +++ b/src/android/amain.c	Fri May 15 02:06:26 2015 +0300
     4.3 @@ -32,7 +32,9 @@
     4.4  	jstring jstr;
     4.5  	int res;
     4.6  
     4.7 -	if(!(foo_id = (*jni)->GetStaticMethodID(jni, activity_class, "foo", "(Ljava/lang/String;I)V"))) {
     4.8 +	printf("call_foo() [activity_class=%p]\n", (void*)activity_class);
     4.9 +
    4.10 +	if(!(foo_id = (*jni)->GetStaticMethodID(jni, activity_class, "foo", "(Ljava/lang/String;I)I"))) {
    4.11  		fprintf(stderr, "static method foo not found\n");
    4.12  		return -1;
    4.13  	}
    4.14 @@ -59,7 +61,7 @@
    4.15  		fprintf(stderr, "failed to attach native thread to Java VM\n");
    4.16  		exit(1);
    4.17  	}
    4.18 -	activity_class = app->activity_class;
    4.19 +	activity_class = (*jni)->GetObjectClass(jni, app->activity->clazz);
    4.20  
    4.21  	printf("JNI call returned: %d\n", call_foo("testing C->java jni calls", 42));
    4.22  
    4.23 @@ -288,3 +290,10 @@
    4.24  	dpy = 0;
    4.25  }
    4.26  
    4.27 +
    4.28 +/*
    4.29 +static jclass get_java_class(const char *name)
    4.30 +{
    4.31 +	jobject native
    4.32 +}
    4.33 +*/
     5.1 --- a/src/android/native_glue.c	Thu May 14 23:46:56 2015 +0300
     5.2 +++ b/src/android/native_glue.c	Fri May 15 02:06:26 2015 +0300
     5.3 @@ -37,6 +37,36 @@
     5.4  #  define LOGV(...)  ((void)0)
     5.5  #endif
     5.6  
     5.7 +/*
     5.8 +jint JNI_OnLoad(JavaVM *jvm, void *unused)
     5.9 +{
    5.10 +	JNIEnv *jni;
    5.11 +	jclass act_cls_local;
    5.12 +
    5.13 +	LOGI("OnLoad called ! <------------------\n");
    5.14 +
    5.15 +	if((*jvm)->GetEnv(jvm, (void**)&jni, JNI_VERSION_1_6) != JNI_OK) {
    5.16 +		LOGE("OnLoad: failed to get JNIEnv from VM\n");
    5.17 +		return -1;
    5.18 +	}
    5.19 +
    5.20 +	jclass foo = (*jni)->FindClass(jni, "java/lang/String");
    5.21 +	if(!foo) {
    5.22 +		LOGE("String class not found!!!!!!\n");
    5.23 +	} else {
    5.24 +		LOGE("Found String class!!!!!!\n");
    5.25 +	}
    5.26 +
    5.27 +	if(!(act_cls_local = (*jni)->FindClass(jni, ACTIVITY_NAME))) {
    5.28 +		LOGE("could not find activity: " ACTIVITY_NAME);
    5.29 +		return 0;
    5.30 +	}
    5.31 +	activity_class = (*jni)->NewGlobalRef(jni, act_cls_local);
    5.32 +
    5.33 +	return JNI_VERSION_1_6;
    5.34 +}
    5.35 +*/
    5.36 +
    5.37  static void free_saved_state(struct android_app* android_app) {
    5.38      pthread_mutex_lock(&android_app->mutex);
    5.39      if (android_app->savedState != NULL) {
    5.40 @@ -180,6 +210,7 @@
    5.41          AInputQueue_detachLooper(android_app->inputQueue);
    5.42      }
    5.43      AConfiguration_delete(android_app->config);
    5.44 +
    5.45      android_app->destroyed = 1;
    5.46      pthread_cond_broadcast(&android_app->cond);
    5.47      pthread_mutex_unlock(&android_app->mutex);
    5.48 @@ -243,25 +274,10 @@
    5.49  
    5.50  static struct android_app* android_app_create(ANativeActivity* activity,
    5.51          void* savedState, size_t savedStateSize) {
    5.52 -	JNIEnv *jni = activity->env;
    5.53      struct android_app* android_app = malloc(sizeof(struct android_app));
    5.54      memset(android_app, 0, sizeof(struct android_app));
    5.55      android_app->activity = activity;
    5.56  
    5.57 -	{
    5.58 -		jclass foo = (*jni)->FindClass(jni, "java/lang/String");
    5.59 -		if(!foo) {
    5.60 -			LOGE("String class not found!!!!!!\n");
    5.61 -		} else {
    5.62 -			LOGE("Found String class!!!!!!\n");
    5.63 -		}
    5.64 -	}
    5.65 -
    5.66 -	if(!(android_app->activity_class = (*jni)->FindClass(jni, ACTIVITY_NAME))) {
    5.67 -		LOGE("could not find activity: " ACTIVITY_NAME);
    5.68 -		return 0;
    5.69 -	}
    5.70 -
    5.71      pthread_mutex_init(&android_app->mutex, NULL);
    5.72      pthread_cond_init(&android_app->cond, NULL);
    5.73  
     6.1 --- a/src/android/native_glue.h	Thu May 14 23:46:56 2015 +0300
     6.2 +++ b/src/android/native_glue.h	Fri May 15 02:06:26 2015 +0300
     6.3 @@ -182,9 +182,6 @@
     6.4      AInputQueue* pendingInputQueue;
     6.5      ANativeWindow* pendingWindow;
     6.6      ARect pendingContentRect;
     6.7 -
     6.8 -	// MainActivity class
     6.9 -	jclass activity_class;
    6.10  };
    6.11  
    6.12  enum {