Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python2 for webview #981

Merged
merged 4 commits into from
Aug 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ public void run() {
nativeResize(mWidth, mHeight);
nativeInitJavaCallbacks();
nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
nativeSetEnv("ANDROID_UNPACK", mFilesDirectory);
nativeSetEnv("ANDROID_ARGUMENT", mArgument);
nativeSetEnv("ANDROID_APP_PATH", mArgument);
nativeSetEnv("PYTHONOPTIMIZE", "2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ protected void onPostExecute(String result) {
String mFilesDirectory = mActivity.getFilesDir().getAbsolutePath();
Log.v(TAG, "Setting env vars for start.c and Python to use");
SDLActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
SDLActivity.nativeSetEnv("ANDROID_UNPACK", mFilesDirectory + "/app");
SDLActivity.nativeSetEnv("PYTHONHOME", app_root_dir);
SDLActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
SDLActivity.nativeSetEnv("PYTHONOPTIMIZE", "2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public abstract class PythonService extends Service implements Runnable {
private String pythonName;
private String pythonHome;
private String pythonPath;
private String androidUnpack;
private String serviceEntrypoint;
private String pythonServiceArgument;

Expand Down Expand Up @@ -70,6 +71,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
pythonName = extras.getString("pythonName");
pythonHome = extras.getString("pythonHome");
pythonPath = extras.getString("pythonPath");
androidUnpack = extras.getString("androidUnpack");
pythonServiceArgument = extras.getString("pythonServiceArgument");

Log.v(TAG, "Starting Python thread");
Expand Down Expand Up @@ -127,7 +129,7 @@ public void onDestroy() {
public void run() {
PythonUtil.loadLibraries(getFilesDir());
nativeStart(androidPrivate, androidArgument, serviceEntrypoint, pythonName, pythonHome,
pythonPath, pythonServiceArgument);
pythonPath, pythonServiceArgument, androidUnpack);
stopSelf();
}

Expand All @@ -143,5 +145,5 @@ public void run() {
public static native void nativeStart(String androidPrivate, String androidArgument,
String serviceEntrypoint, String pythonName,
String pythonHome, String pythonPath,
String pythonServiceArgument);
String pythonServiceArgument, String androidUnpack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static void start(Context ctx, String pythonServiceArgument) {
intent.putExtra("serviceDescription", "");
intent.putExtra("pythonName", "{{ name }}");
intent.putExtra("pythonHome", argument);
intent.putExtra("androidUnpack", argument);
intent.putExtra("pythonPath", argument + ":" + argument + "/lib");
intent.putExtra("pythonServiceArgument", pythonServiceArgument);
ctx.startService(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
PythonActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
PythonActivity.nativeSetEnv("ANDROID_ARGUMENT", mFilesDirectory);
PythonActivity.nativeSetEnv("ANDROID_APP_PATH", mFilesDirectory);
PythonActivity.nativeSetEnv("ANDROID_UNPACK", mFilesDirectory);
PythonActivity.nativeSetEnv("ANDROID_ENTRYPOINT", "main.pyo");
PythonActivity.nativeSetEnv("PYTHONHOME", mFilesDirectory);
PythonActivity.nativeSetEnv("PYTHONPATH", mFilesDirectory + ":" + mFilesDirectory + "/lib");
Expand Down
4 changes: 2 additions & 2 deletions pythonforandroid/recipes/python2/patches/custom-loader.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
+
+ /* Ensure we have access to libpymodules. */
+ if (libpymodules == -1) {
+ printf("ANDROID_APP_PATH = %s\n", getenv("ANDROID_APP_PATH"));
+ PyOS_snprintf(pathbuf, sizeof(pathbuf), "%s/libpymodules.so", getenv("ANDROID_APP_PATH"));
+ printf("ANDROID_UNPACK = %s\n", getenv("ANDROID_UNPACK"));
+ PyOS_snprintf(pathbuf, sizeof(pathbuf), "%s/libpymodules.so", getenv("ANDROID_UNPACK"));
+ libpymodules = dlopen(pathbuf, RTLD_NOW);
+
+ if (libpymodules == NULL) {
Expand Down