diff --git a/pythonforandroid/bootstraps/service_only/build/jni/application/src/pyjniusjni.c b/pythonforandroid/bootstraps/common/build/jni/application/src/pyjniusjni.c similarity index 100% rename from pythonforandroid/bootstraps/service_only/build/jni/application/src/pyjniusjni.c rename to pythonforandroid/bootstraps/common/build/jni/application/src/pyjniusjni.c diff --git a/pythonforandroid/bootstraps/qt/build/jni/application/src/Android.mk b/pythonforandroid/bootstraps/qt/build/jni/application/src/Android.mk index aebe3f623b..bf46570a08 100644 --- a/pythonforandroid/bootstraps/qt/build/jni/application/src/Android.mk +++ b/pythonforandroid/bootstraps/qt/build/jni/application/src/Android.mk @@ -5,7 +5,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := main_$(PREFERRED_ABI) # Add your application source files here... -LOCAL_SRC_FILES := start.c +LOCAL_SRC_FILES := start.c pyjniusjni.c LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS) diff --git a/pythonforandroid/bootstraps/qt/build/jni/application/src/Android_static.mk b/pythonforandroid/bootstraps/qt/build/jni/application/src/Android_static.mk deleted file mode 100644 index 1bb58cb76d..0000000000 --- a/pythonforandroid/bootstraps/qt/build/jni/application/src/Android_static.mk +++ /dev/null @@ -1,9 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := main_$(PREFERRED_ABI) - -LOCAL_SRC_FILES := start.c - -include $(BUILD_SHARED_LIBRARY) diff --git a/pythonforandroid/bootstraps/sdl2/build/jni/application/src/Android_static.mk b/pythonforandroid/bootstraps/sdl2/build/jni/application/src/Android_static.mk deleted file mode 100644 index 517660be2a..0000000000 --- a/pythonforandroid/bootstraps/sdl2/build/jni/application/src/Android_static.mk +++ /dev/null @@ -1,12 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := main - -LOCAL_SRC_FILES := start.c - -LOCAL_STATIC_LIBRARIES := SDL2_static - -include $(BUILD_SHARED_LIBRARY) -$(call import-module,SDL)LOCAL_PATH := $(call my-dir) diff --git a/pythonforandroid/bootstraps/sdl3/build/jni/application/src/Android_static.mk b/pythonforandroid/bootstraps/sdl3/build/jni/application/src/Android_static.mk deleted file mode 100644 index f4ff2462e6..0000000000 --- a/pythonforandroid/bootstraps/sdl3/build/jni/application/src/Android_static.mk +++ /dev/null @@ -1,13 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := main - -LOCAL_SRC_FILES := start.c - -LOCAL_STATIC_LIBRARIES := SDL3_static - - -include $(BUILD_SHARED_LIBRARY) -$(call import-module,SDL)LOCAL_PATH := $(call my-dir) diff --git a/pythonforandroid/bootstraps/service_only/build/jni/application/src/Android_static.mk b/pythonforandroid/bootstraps/service_only/build/jni/application/src/Android_static.mk deleted file mode 100644 index 2de278ee00..0000000000 --- a/pythonforandroid/bootstraps/service_only/build/jni/application/src/Android_static.mk +++ /dev/null @@ -1,10 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := main - -LOCAL_SRC_FILES := YourSourceHere.c - -include $(BUILD_SHARED_LIBRARY) -$(call import-module,SDL)LOCAL_PATH := $(call my-dir) diff --git a/pythonforandroid/bootstraps/webview/build/jni/application/src/Android_static.mk b/pythonforandroid/bootstraps/webview/build/jni/application/src/Android_static.mk deleted file mode 100644 index faed669c0e..0000000000 --- a/pythonforandroid/bootstraps/webview/build/jni/application/src/Android_static.mk +++ /dev/null @@ -1,12 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := main - -LOCAL_SRC_FILES := YourSourceHere.c - -LOCAL_STATIC_LIBRARIES := SDL2_static - -include $(BUILD_SHARED_LIBRARY) -$(call import-module,SDL)LOCAL_PATH := $(call my-dir) diff --git a/pythonforandroid/bootstraps/webview/build/jni/application/src/pyjniusjni.c b/pythonforandroid/bootstraps/webview/build/jni/application/src/pyjniusjni.c deleted file mode 100644 index d67972a4db..0000000000 --- a/pythonforandroid/bootstraps/webview/build/jni/application/src/pyjniusjni.c +++ /dev/null @@ -1,103 +0,0 @@ - -#include -#include - -#define LOGI(...) do {} while (0) -#define LOGE(...) do {} while (0) - -#include "android/log.h" - -/* These JNI management functions are taken from SDL2, but modified to refer to pyjnius */ - -/* #define LOG(n, x) __android_log_write(ANDROID_LOG_INFO, (n), (x)) */ -/* #define LOGP(x) LOG("python", (x)) */ -#define LOG_TAG "Python_android" -#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) -#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) - - -/* Function headers */ -JNIEnv* Android_JNI_GetEnv(void); -static void Android_JNI_ThreadDestroyed(void*); - -static pthread_key_t mThreadKey; -static JavaVM* mJavaVM; - -int Android_JNI_SetupThread(void) -{ - Android_JNI_GetEnv(); - return 1; -} - -/* Library init */ -JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) -{ - JNIEnv *env; - mJavaVM = vm; - LOGI("JNI_OnLoad called"); - if ((*mJavaVM)->GetEnv(mJavaVM, (void**) &env, JNI_VERSION_1_4) != JNI_OK) { - LOGE("Failed to get the environment using GetEnv()"); - return -1; - } - /* - * Create mThreadKey so we can keep track of the JNIEnv assigned to each thread - * Refer to http://developer.android.com/guide/practices/design/jni.html for the rationale behind this - */ - if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed) != 0) { - - __android_log_print(ANDROID_LOG_ERROR, "pyjniusjni", "Error initializing pthread key"); - } - Android_JNI_SetupThread(); - - return JNI_VERSION_1_4; -} - -JNIEnv* Android_JNI_GetEnv(void) -{ - /* From http://developer.android.com/guide/practices/jni.html - * All threads are Linux threads, scheduled by the kernel. - * They're usually started from managed code (using Thread.start), but they can also be created elsewhere and then - * attached to the JavaVM. For example, a thread started with pthread_create can be attached with the - * JNI AttachCurrentThread or AttachCurrentThreadAsDaemon functions. Until a thread is attached, it has no JNIEnv, - * and cannot make JNI calls. - * Attaching a natively-created thread causes a java.lang.Thread object to be constructed and added to the "main" - * ThreadGroup, making it visible to the debugger. Calling AttachCurrentThread on an already-attached thread - * is a no-op. - * Note: You can call this function any number of times for the same thread, there's no harm in it - */ - - JNIEnv *env; - int status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL); - if(status < 0) { - LOGE("failed to attach current thread"); - return 0; - } - - /* From http://developer.android.com/guide/practices/jni.html - * Threads attached through JNI must call DetachCurrentThread before they exit. If coding this directly is awkward, - * in Android 2.0 (Eclair) and higher you can use pthread_key_create to define a destructor function that will be - * called before the thread exits, and call DetachCurrentThread from there. (Use that key with pthread_setspecific - * to store the JNIEnv in thread-local-storage; that way it'll be passed into your destructor as the argument.) - * Note: The destructor is not called unless the stored value is != NULL - * Note: You can call this function any number of times for the same thread, there's no harm in it - * (except for some lost CPU cycles) - */ - pthread_setspecific(mThreadKey, (void*) env); - - return env; -} - -static void Android_JNI_ThreadDestroyed(void* value) -{ - /* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */ - JNIEnv *env = (JNIEnv*) value; - if (env != NULL) { - (*mJavaVM)->DetachCurrentThread(mJavaVM); - pthread_setspecific(mThreadKey, NULL); - } -} - -void *WebView_AndroidGetJNIEnv() -{ - return Android_JNI_GetEnv(); -}