14
14
#include <sys/types.h>
15
15
#include <errno.h>
16
16
17
+ #include "bootstrap_name.h"
18
+ #ifndef BOOTSTRAP_USES_NO_SDL_HEADERS
17
19
#include "SDL.h"
18
- #include "android/log.h"
19
20
#include "SDL_opengles2.h"
21
+ #endif
22
+ #ifdef BOOTSTRAP_NAME_PYGAME
23
+ #include "jniwrapperstuff.h"
24
+ #endif
25
+ #include "android/log.h"
20
26
21
27
#define ENTRYPOINT_MAXLEN 128
22
28
#define LOG (n , x ) __android_log_write(ANDROID_LOG_INFO, (n), (x))
@@ -76,7 +82,7 @@ int main(int argc, char *argv[]) {
76
82
int ret = 0 ;
77
83
FILE * fd ;
78
84
79
- setenv ("P4A_BOOTSTRAP" , "SDL2" , 1 ); // env var to identify p4a to applications
85
+ setenv ("P4A_BOOTSTRAP" , bootstrap_name , 1 ); // env var to identify p4a to applications
80
86
81
87
LOGP ("Initializing Python for Android" );
82
88
env_argument = getenv ("ANDROID_ARGUMENT" );
@@ -135,7 +141,6 @@ int main(int argc, char *argv[]) {
135
141
LOGP ("calculated paths to be..." );
136
142
LOGP (paths );
137
143
138
-
139
144
#if PY_MAJOR_VERSION >= 3
140
145
wchar_t * wchar_paths = Py_DecodeLocale (paths , NULL );
141
146
Py_SetPath (wchar_paths );
@@ -179,7 +184,7 @@ int main(int argc, char *argv[]) {
179
184
PyRun_SimpleString ("import sys, posix\n" );
180
185
if (dir_exists ("lib" )) {
181
186
/* If we built our own python, set up the paths correctly */
182
- LOGP ("Setting up python from ANDROID_PRIVATE " );
187
+ LOGP ("Setting up python from ANDROID_APP_PATH " );
183
188
PyRun_SimpleString ("private = posix.environ['ANDROID_APP_PATH']\n"
184
189
"argument = posix.environ['ANDROID_ARGUMENT']\n"
185
190
"sys.path[:] = [ \n"
@@ -318,19 +323,30 @@ int main(int argc, char *argv[]) {
318
323
}
319
324
320
325
JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart (
321
- JNIEnv * env , jobject thiz , jstring j_android_private ,
322
- jstring j_android_argument , jstring j_service_entrypoint ,
323
- jstring j_python_name , jstring j_python_home , jstring j_python_path ,
326
+ JNIEnv * env ,
327
+ jobject thiz ,
328
+ jstring j_android_private ,
329
+ jstring j_android_argument ,
330
+ #if (!defined(BOOTSTRAP_NAME_PYGAME ))
331
+ jstring j_service_entrypoint ,
332
+ jstring j_python_name ,
333
+ #endif
334
+ jstring j_python_home ,
335
+ jstring j_python_path ,
324
336
jstring j_arg ) {
325
337
jboolean iscopy ;
326
338
const char * android_private =
327
339
(* env )-> GetStringUTFChars (env , j_android_private , & iscopy );
328
340
const char * android_argument =
329
341
(* env )-> GetStringUTFChars (env , j_android_argument , & iscopy );
342
+ #if (!defined(BOOTSTRAP_NAME_PYGAME ))
330
343
const char * service_entrypoint =
331
344
(* env )-> GetStringUTFChars (env , j_service_entrypoint , & iscopy );
332
345
const char * python_name =
333
346
(* env )-> GetStringUTFChars (env , j_python_name , & iscopy );
347
+ #else
348
+ const char python_name [] = "python2" ;
349
+ #endif
334
350
const char * python_home =
335
351
(* env )-> GetStringUTFChars (env , j_python_home , & iscopy );
336
352
const char * python_path =
@@ -340,13 +356,16 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
340
356
setenv ("ANDROID_PRIVATE" , android_private , 1 );
341
357
setenv ("ANDROID_ARGUMENT" , android_argument , 1 );
342
358
setenv ("ANDROID_APP_PATH" , android_argument , 1 );
359
+
360
+ #if (!defined(BOOTSTRAP_NAME_PYGAME ))
343
361
setenv ("ANDROID_ENTRYPOINT" , service_entrypoint , 1 );
362
+ #endif
344
363
setenv ("PYTHONOPTIMIZE" , "2" , 1 );
345
364
setenv ("PYTHON_NAME" , python_name , 1 );
346
365
setenv ("PYTHONHOME" , python_home , 1 );
347
366
setenv ("PYTHONPATH" , python_path , 1 );
348
367
setenv ("PYTHON_SERVICE_ARGUMENT" , arg , 1 );
349
- setenv ("P4A_BOOTSTRAP" , "SDL2" , 1 );
368
+ setenv ("P4A_BOOTSTRAP" , bootstrap_name , 1 );
350
369
351
370
char * argv [] = {"." };
352
371
/* ANDROID_ARGUMENT points to service subdir,
@@ -355,4 +374,46 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
355
374
main (1 , argv );
356
375
}
357
376
377
+ #ifdef BOOTSTRAP_NAME_WEBVIEW
378
+ // Webview uses some more functions:
379
+
380
+ void Java_org_kivy_android_PythonActivity_nativeSetEnv (
381
+ JNIEnv * env , jclass jcls ,
382
+ jstring j_name , jstring j_value )
383
+ /* JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeSetEnv( */
384
+ /* JNIEnv* env, jclass jcls, */
385
+ /* jstring j_name, jstring j_value) */
386
+ {
387
+ jboolean iscopy ;
388
+ const char * name = (* env )-> GetStringUTFChars (env , j_name , & iscopy );
389
+ const char * value = (* env )-> GetStringUTFChars (env , j_value , & iscopy );
390
+ setenv (name , value , 1 );
391
+ (* env )-> ReleaseStringUTFChars (env , j_name , name );
392
+ (* env )-> ReleaseStringUTFChars (env , j_value , value );
393
+ }
394
+
395
+
396
+ void Java_org_kivy_android_PythonActivity_nativeInit (JNIEnv * env , jclass cls , jobject obj )
397
+ {
398
+ /* This nativeInit follows SDL2 */
399
+
400
+ /* This interface could expand with ABI negotiation, calbacks, etc. */
401
+ /* SDL_Android_Init(env, cls); */
402
+
403
+ /* SDL_SetMainReady(); */
404
+
405
+ /* Run the application code! */
406
+ int status ;
407
+ char * argv [2 ];
408
+ argv [0 ] = "Python_app" ;
409
+ argv [1 ] = NULL ;
410
+ /* status = SDL_main(1, argv); */
411
+
412
+ main (1 , argv );
413
+
414
+ /* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
415
+ /* exit(status); */
416
+ }
417
+ #endif
418
+
358
419
#endif
0 commit comments