summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--src/app.c26
-rw-r--r--src/libjvm-android.c17
3 files changed, 43 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index af4ffb0..951bca5 100644
--- a/Makefile
+++ b/Makefile
@@ -39,6 +39,9 @@ runtime/libandroid.so: runtime src/libandroid.c
runtime/liblog.so: runtime src/liblog.c
native: runtime/libc.so runtime/libpthread.so runtime/libandroid.so runtime/liblog.so
+runtime/libjvm-android.so: runtime src/libjvm-android.c
+java: runtime/libjvm-android.so
+
linker.a: CFLAGS += -D_GNU_SOURCE -DANDROID_X86_LINKER -DLINKER_DEBUG=1
linker.a: CFLAGS += -Wno-pedantic -Wno-variadic-macros -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast
linker.a: src/linker/dlfcn.o src/linker/linker.o src/linker/linker_environ.o src/linker/rt.o src/linker/strlcpy.o
@@ -47,7 +50,7 @@ jvm.a: CFLAGS += -Wno-unused-variable -Wno-pedantic
jvm.a: src/jvm/jvm.o
app: private LDLIBS += -ldl -Wl,-rpath,runtime
-app: src/app.c linker.a native jvm.a
+app: src/app.c linker.a native jvm.a java
install-bin: $(bins)
install -Dm755 $^ -t "$(DESTDIR)$(PREFIX)$(BINDIR)"
diff --git a/src/app.c b/src/app.c
index dbcdfe9..b3892d2 100644
--- a/src/app.c
+++ b/src/app.c
@@ -8,6 +8,7 @@
extern void *apkenv_android_dlopen(const char*, int);
extern void *apkenv_android_dlclose(void*);
+extern const char *apkenv_android_dlerror(void);
extern void *apkenv_android_dlsym(void*, const char*);
extern void apkenv_parse_library_path(const char *path, char *delim);
@@ -18,7 +19,9 @@ main(int argc, const char *argv[])
errx(EXIT_FAILURE, "usage: so-file");
printf("loading runtime\n");
- dlopen("libpthread.so", RTLD_NOW | RTLD_GLOBAL);
+ if (!dlopen("libpthread.so", RTLD_NOW | RTLD_GLOBAL) ||
+ !dlopen("libjvm-android.so", RTLD_NOW | RTLD_GLOBAL))
+ errx(EXIT_FAILURE, "%s", dlerror());
printf("loading module: %s\n", argv[1]);
@@ -31,12 +34,13 @@ main(int argc, const char *argv[])
{
void *handle;
if (!(handle = apkenv_android_dlopen(argv[1], RTLD_NOW | RTLD_LOCAL)))
- errx(EXIT_FAILURE, "dlopen failed: %s", dlerror());
+ errx(EXIT_FAILURE, "dlopen failed: %s", apkenv_android_dlerror());
printf("trying JNI_OnLoad from: %s\n", argv[1]);
struct jvm jvm;
jvm_init(&jvm);
+ const jobject context = jvm.native.AllocObject(&jvm.env, jvm.native.FindClass(&jvm.env, "android/content/context"));
void* (*JNI_OnLoad)(void*, void*) = apkenv_android_dlsym(handle, "JNI_OnLoad");
assert(JNI_OnLoad);
@@ -44,8 +48,22 @@ main(int argc, const char *argv[])
JNI_OnLoad(&jvm.vm, NULL);
static const char *unity_player_class = "com/unity3d/player/UnityPlayer";
- void (*native_init)(void*, void*, int, int) = jvm_get_native_method(&jvm, unity_player_class, "initJni");
- native_init(&jvm.env, (jclass)1, 1024, 768);
+ void (*native_init)(JNIEnv*, jobject, jobject) = jvm_get_native_method(&jvm, unity_player_class, "initJni");
+ void (*native_file)(JNIEnv*, jobject, jstring) = jvm_get_native_method(&jvm, unity_player_class, "nativeFile");
+ jboolean (*native_pause)(JNIEnv*, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativePause");
+ void (*native_done)(JNIEnv*, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativeDone");
+ void (*native_recreate_gfx_state)(JNIEnv*, jobject, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativeRecreateGfxState");
+ void (*native_resume)(JNIEnv*, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativeResume");
+ jboolean (*native_render)(JNIEnv*, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativeRender");
+ void (*native_focus_changed)(JNIEnv*, jobject, jboolean) = jvm_get_native_method(&jvm, unity_player_class, "nativeFocusChanged");
+ void (*native_set_input_string)(JNIEnv*, jobject, jstring) = jvm_get_native_method(&jvm, unity_player_class, "nativeSetInputString");
+ void (*native_soft_input_closed)(JNIEnv*, jobject) = jvm_get_native_method(&jvm, unity_player_class, "nativeSoftInputClosed");
+ void (*native_soft_input_canceled)(JNIEnv*, jobject, jboolean) = jvm_get_native_method(&jvm, unity_player_class, "nativeSoftInputCanceled");
+ native_init(&jvm.env, context, context);
+ native_file(&jvm.env, context, jvm.native.NewStringUTF(&jvm.env, "./file.apk"));
+ native_done(&jvm.env, context);
+ native_recreate_gfx_state(&jvm.env, context, context);
+ native_render(&jvm.env, (jobject)1);
printf("unloading module: %s\n", argv[1]);
apkenv_android_dlclose(handle);
diff --git a/src/libjvm-android.c b/src/libjvm-android.c
new file mode 100644
index 0000000..ddf3be5
--- /dev/null
+++ b/src/libjvm-android.c
@@ -0,0 +1,17 @@
+#include <assert.h>
+#include "jvm/jni.h"
+
+jstring
+android_content_Context_getPackageName(JNIEnv *env, jobject object, va_list args)
+{
+ assert(env && object);
+ return (*env)->NewStringUTF(env, "com.gnu.linux");
+}
+
+jstring
+android_content_context_getPackageName(JNIEnv *env, jobject object, va_list args)
+{
+ // Probably bug in unity, call to lowercase context class, but works due to case-insensitive filesystem.
+ // <https://stackoverflow.com/questions/10890805/case-sensitivity-of-java-class-names>
+ return android_content_Context_getPackageName(env, object, args);
+}