Python logging (#7)
Service code cleanup. Kivy dependency eliminated. File and stdout logging working properly.
This commit is contained in:
parent
f211b0df99
commit
80aeb406af
11 changed files with 195 additions and 100 deletions
p4a/pythonforandroid/bootstraps/lbry
|
@ -7,13 +7,13 @@ import sh
|
|||
class LbryBootstrap(Bootstrap):
|
||||
name = 'lbry'
|
||||
|
||||
recipe_depends = ['sdl2', ('python2', 'python3crystax')]
|
||||
recipe_depends = ['genericndkbuild', ('python2', 'python3crystax')]
|
||||
|
||||
def run_distribute(self):
|
||||
info_main('# Creating Android project from build and {} bootstrap'.format(
|
||||
self.name))
|
||||
|
||||
info('This currently just copies the SDL2 build stuff straight from the build dir.')
|
||||
info('This currently just copies the build stuff straight from the build dir.')
|
||||
shprint(sh.rm, '-rf', self.dist_dir)
|
||||
shprint(sh.cp, '-r', self.build_dir, self.dist_dir)
|
||||
with current_directory(self.dist_dir):
|
||||
|
|
|
@ -4,19 +4,14 @@ include $(CLEAR_VARS)
|
|||
|
||||
LOCAL_MODULE := main
|
||||
|
||||
SDL_PATH := ../SDL
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
|
||||
|
||||
# Add your application source files here...
|
||||
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
|
||||
start.c
|
||||
LOCAL_SRC_FILES := start.c pyjniusjni.c
|
||||
|
||||
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := SDL2 python_shared
|
||||
LOCAL_SHARED_LIBRARIES := python_shared
|
||||
|
||||
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
|
||||
LOCAL_LDLIBS := -llog $(EXTRA_LDLIBS)
|
||||
|
||||
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
|
||||
|
||||
|
|
|
@ -6,7 +6,5 @@ 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)
|
||||
|
|
103
p4a/pythonforandroid/bootstraps/lbry/build/jni/src/pyjniusjni.c
Normal file
103
p4a/pythonforandroid/bootstraps/lbry/build/jni/src/pyjniusjni.c
Normal file
|
@ -0,0 +1,103 @@
|
|||
|
||||
#include <pthread.h>
|
||||
#include <jni.h>
|
||||
|
||||
#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();
|
||||
}
|
|
@ -14,9 +14,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "android/log.h"
|
||||
#include "SDL_opengles2.h"
|
||||
|
||||
#define ENTRYPOINT_MAXLEN 128
|
||||
#define LOG(n, x) __android_log_write(ANDROID_LOG_INFO, (n), (x))
|
||||
|
@ -84,7 +82,7 @@ int main(int argc, char *argv[]) {
|
|||
setenv("ANDROID_APP_PATH", env_argument, 1);
|
||||
env_entrypoint = getenv("ANDROID_ENTRYPOINT");
|
||||
env_logname = getenv("PYTHON_NAME");
|
||||
|
||||
|
||||
if (env_logname == NULL) {
|
||||
env_logname = "python";
|
||||
setenv("PYTHON_NAME", "python", 1);
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
apply plugin: 'com.android.model.application'
|
||||
|
||||
model {
|
||||
android {
|
||||
compileSdkVersion {{ args.sdk_version }}
|
||||
buildToolsVersion "23.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "{{ args.package }}"
|
||||
minSdkVersion.apiLevel {{ args.min_sdk_version }}
|
||||
targetSdkVersion.apiLevel {{ args.sdk_version }}
|
||||
versionCode {{ args.numeric_version }}
|
||||
versionName "{{ args.version }}"
|
||||
|
||||
buildConfigFields {
|
||||
create() {
|
||||
type "int"
|
||||
name "VALUE"
|
||||
value "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
ndk {
|
||||
abiFilters.add("armeabi-v7a")
|
||||
moduleName = "main"
|
||||
toolchain = "gcc"
|
||||
toolchainVersion = "4.9"
|
||||
platformVersion = 16
|
||||
stl = "gnustl_shared"
|
||||
renderscriptNdkMode = false
|
||||
CFlags.add("-I" + file("src/main/jni/include/python2.7"))
|
||||
ldFlags.add("-L" + file("src/main/jni/lib"))
|
||||
ldLibs.addAll(["log", "python2.7"])
|
||||
}
|
||||
// Configures source set directory.
|
||||
sources {
|
||||
main {
|
||||
jniLibs {
|
||||
dependencies {
|
||||
library "gnustl_shared"
|
||||
// add pre-built libraries here and locate them below:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
libs(PrebuiltLibraries) {
|
||||
gnustl_shared {
|
||||
binaries.withType(SharedLibraryBinary) {
|
||||
sharedLibraryFile = file("src/main/jniLibs/${targetPlatform.getName()}/libgnustl_shared.so")
|
||||
}
|
||||
}
|
||||
// more here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// normal project dependencies here
|
Loading…
Add table
Add a link
Reference in a new issue