Skip to content

Commit ceb06d7

Browse files
author
lanmao
committed
Save local p4a custom changes
1 parent ff90c8a commit ceb06d7

13 files changed

Lines changed: 942 additions & 160 deletions

File tree

pythonforandroid/bootstraps/qt/build/jni/application/src/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include $(CLEAR_VARS)
55
LOCAL_MODULE := main_$(PREFERRED_ABI)
66

77
# Add your application source files here...
8-
LOCAL_SRC_FILES := start.c
8+
LOCAL_SRC_FILES := start.c pyjniusjni.c
99

1010
LOCAL_CFLAGS += -I$(PYTHON_INCLUDE_ROOT) $(EXTRA_CFLAGS)
1111

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <pthread.h>
2+
#include <jni.h>
3+
#include "android/log.h"
4+
5+
#define LOG_TAG "Python_android"
6+
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
7+
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
8+
9+
JNIEnv* Android_JNI_GetEnv(void);
10+
static void Android_JNI_ThreadDestroyed(void*);
11+
12+
static pthread_key_t mThreadKey;
13+
static JavaVM* mJavaVM;
14+
15+
int Android_JNI_SetupThread(void)
16+
{
17+
Android_JNI_GetEnv();
18+
return 1;
19+
}
20+
21+
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
22+
{
23+
JNIEnv *env;
24+
mJavaVM = vm;
25+
LOGI("JNI_OnLoad called");
26+
if ((*mJavaVM)->GetEnv(mJavaVM, (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
27+
LOGE("Failed to get the environment using GetEnv()");
28+
return -1;
29+
}
30+
31+
if (pthread_key_create(&mThreadKey, Android_JNI_ThreadDestroyed) != 0) {
32+
__android_log_print(ANDROID_LOG_ERROR, "pyjniusjni", "Error initializing pthread key");
33+
}
34+
Android_JNI_SetupThread();
35+
36+
return JNI_VERSION_1_4;
37+
}
38+
39+
JNIEnv* Android_JNI_GetEnv(void)
40+
{
41+
JNIEnv *env;
42+
int status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL);
43+
if(status < 0) {
44+
LOGE("failed to attach current thread");
45+
return 0;
46+
}
47+
48+
pthread_setspecific(mThreadKey, (void*) env);
49+
50+
return env;
51+
}
52+
53+
static void Android_JNI_ThreadDestroyed(void* value)
54+
{
55+
JNIEnv *env = (JNIEnv*) value;
56+
if (env != NULL) {
57+
(*mJavaVM)->DetachCurrentThread(mJavaVM);
58+
pthread_setspecific(mThreadKey, NULL);
59+
}
60+
}
61+
62+
void *WebView_AndroidGetJNIEnv()
63+
{
64+
return Android_JNI_GetEnv();
65+
}

pythonforandroid/bootstraps/qt/build/src/main/java/org/kivy/android/PythonActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ public void onDestroy() {
122122

123123
@Override
124124
public boolean onKeyDown(int keyCode, KeyEvent event) {
125-
// If it wasn't the Back key or there's no web page history, bubble up to the default
126-
// system behavior (probably exit the activity)
125+
if (keyCode != KeyEvent.KEYCODE_BACK) {
126+
return super.onKeyDown(keyCode, event);
127+
}
128+
127129
if (SystemClock.elapsedRealtime() - lastBackClick > 2000) {
128130
lastBackClick = SystemClock.elapsedRealtime();
129131
Toast.makeText(this, "Click again to close the app", Toast.LENGTH_LONG).show();

pythonforandroid/distribution.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def get_distribution(
9292
'''
9393

9494
possible_dists = Distribution.get_distributions(ctx)
95+
requested_recipes = {recipe.lower() for recipe in recipes}
9596
debug(f"All possible dists: {possible_dists}")
9697

9798
# Will hold dists that would be built in the same folder as an existing dist
@@ -115,6 +116,7 @@ def get_distribution(
115116
# 1) Check if any existing dists meet the requirements
116117
_possible_dists = []
117118
for dist in possible_dists:
119+
dist_recipes = {recipe.lower() for recipe in dist.recipes}
118120
if (
119121
ndk_api is not None and dist.ndk_api != ndk_api
120122
) or dist.ndk_api is None:
@@ -123,7 +125,7 @@ def get_distribution(
123125
)
124126
continue
125127
for recipe in recipes:
126-
if recipe not in dist.recipes:
128+
if recipe.lower() not in dist_recipes:
127129
debug(f"dist {dist} missing recipe {recipe}")
128130
break
129131
else:
@@ -149,8 +151,9 @@ def get_distribution(
149151
if not all(arch_name in dist.archs for arch_name in archs):
150152
debug("Skipping dist due to arch mismatch")
151153
continue
152-
if (set(dist.recipes) == set(recipes) or
153-
(set(recipes).issubset(set(dist.recipes)) and
154+
dist_recipes = {recipe.lower() for recipe in dist.recipes}
155+
if (dist_recipes == requested_recipes or
156+
(requested_recipes.issubset(dist_recipes) and
154157
not require_perfect_match)):
155158
info_notify('{} has compatible recipes, using this one'
156159
.format(dist.name))

pythonforandroid/meson_python.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ def handle_python_info():
1818

1919
prefix = C.TARGET_PYTHON_PREFIX
2020

21-
sysconfig_file = glob(join(prefix, "lib/python3.14/_sysconfigdata*.py"))[0]
21+
ver_python = f"python{C.PYTHON_MAJOR_VERSION}.{C.PYTHON_MINOR_VERSION}"
22+
sysconfig_file = glob(join(prefix, f"lib/{ver_python}/_sysconfigdata*.py"))[0]
2223

2324
spec = importlib.util.spec_from_file_location("_android_cfg", sysconfig_file)
2425
cfg = importlib.util.module_from_spec(spec)
2526
spec.loader.exec_module(cfg)
2627

27-
ver_python = f"python{C.PYTHON_MAJOR_VERSION}.{C.PYTHON_MINOR_VERSION}"
28-
2928
site_path = join(prefix, f"lib/{ver_python}/site-packages")
3029

3130
android_paths = {

0 commit comments

Comments
 (0)