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

Use nativeSetenv() provided by SDL2 and cleanups #1690

Merged
merged 1 commit into from
Feb 7, 2019
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 @@ -458,19 +458,20 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
#if defined(BOOTSTRAP_NAME_WEBVIEW) || defined(BOOTSTRAP_NAME_SERVICEONLY)
// Webview and service_only uses some more functions:

void Java_org_kivy_android_PythonActivity_nativeSetEnv(
JNIEnv* env, jclass jcls,
jstring j_name, jstring j_value)
/* JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_nativeSetEnv( */
/* JNIEnv* env, jclass jcls, */
/* jstring j_name, jstring j_value) */
void Java_org_kivy_android_PythonActivity_nativeSetenv(
JNIEnv* env, jclass cls,
jstring name, jstring value)
//JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetenv)(
// JNIEnv* env, jclass cls,
// jstring name, jstring value)
{
jboolean iscopy;
const char *name = (*env)->GetStringUTFChars(env, j_name, &iscopy);
const char *value = (*env)->GetStringUTFChars(env, j_value, &iscopy);
setenv(name, value, 1);
(*env)->ReleaseStringUTFChars(env, j_name, name);
(*env)->ReleaseStringUTFChars(env, j_value, value);
const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
const char *utfvalue = (*env)->GetStringUTFChars(env, value, NULL);

SDL_setenv(utfname, utfvalue, 1);

(*env)->ReleaseStringUTFChars(env, name, utfname);
(*env)->ReleaseStringUTFChars(env, value, utfvalue);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ protected void onPostExecute(String result) {

Project p = Project.scanDirectory(path);
String entry_point = getEntryPoint(p.dir);
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", p.dir + "/" + entry_point);
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", p.dir);
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", p.dir);
SDLActivity.nativeSetenv("ANDROID_ENTRYPOINT", p.dir + "/" + entry_point);
SDLActivity.nativeSetenv("ANDROID_ARGUMENT", p.dir);
SDLActivity.nativeSetenv("ANDROID_APP_PATH", p.dir);

if (p != null) {
if (p.landscape) {
Expand All @@ -173,18 +173,18 @@ protected void onPostExecute(String result) {
}
} else {
String entry_point = getEntryPoint(app_root_dir);
SDLActivity.nativeSetEnv("ANDROID_ENTRYPOINT", entry_point);
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir);
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir);
SDLActivity.nativeSetenv("ANDROID_ENTRYPOINT", entry_point);
SDLActivity.nativeSetenv("ANDROID_ARGUMENT", app_root_dir);
SDLActivity.nativeSetenv("ANDROID_APP_PATH", app_root_dir);
}

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", app_root_dir);
SDLActivity.nativeSetEnv("PYTHONHOME", app_root_dir);
SDLActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
SDLActivity.nativeSetEnv("PYTHONOPTIMIZE", "2");
SDLActivity.nativeSetenv("ANDROID_PRIVATE", mFilesDirectory);
SDLActivity.nativeSetenv("ANDROID_UNPACK", app_root_dir);
SDLActivity.nativeSetenv("PYTHONHOME", app_root_dir);
SDLActivity.nativeSetenv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
SDLActivity.nativeSetenv("PYTHONOPTIMIZE", "2");

try {
Log.v(TAG, "Access to our meta-data...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
Message msg = commandHandler.obtainMessage();
msg.arg1 = command;
msg.obj = data;
@@ -709,6 +718,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
public static native void nativeResume();
public static native void onNativeDropFile(String filename);
public static native void onNativeResize(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, int format, float rate);
+ public static native void nativeSetEnv(String j_name, String j_value);
public static native void onNativeKeyDown(int keycode);
public static native void onNativeKeyUp(int keycode);
public static native void onNativeKeyboardFocusLost();
@@ -1051,6 +1061,21 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
return Arrays.copyOf(filtered, used);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ public void onClick(DialogInterface dialog,int id) {
String entry_point = getEntryPoint(app_root_dir);

Log.v(TAG, "Setting env vars for start.c and Python to use");
PythonActivity.nativeSetEnv("ANDROID_ENTRYPOINT", entry_point);
PythonActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir);
PythonActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir);
PythonActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
PythonActivity.nativeSetEnv("ANDROID_UNPACK", app_root_dir);
PythonActivity.nativeSetEnv("PYTHONHOME", app_root_dir);
PythonActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
PythonActivity.nativeSetEnv("PYTHONOPTIMIZE", "2");
PythonActivity.nativeSetenv("ANDROID_ENTRYPOINT", entry_point);
PythonActivity.nativeSetenv("ANDROID_ARGUMENT", app_root_dir);
PythonActivity.nativeSetenv("ANDROID_APP_PATH", app_root_dir);
PythonActivity.nativeSetenv("ANDROID_PRIVATE", mFilesDirectory);
PythonActivity.nativeSetenv("ANDROID_UNPACK", app_root_dir);
PythonActivity.nativeSetenv("PYTHONHOME", app_root_dir);
PythonActivity.nativeSetenv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
PythonActivity.nativeSetenv("PYTHONOPTIMIZE", "2");

try {
Log.v(TAG, "Access to our meta-data...");
Expand Down Expand Up @@ -404,7 +404,7 @@ public static void stop_service() {
}


public static native void nativeSetEnv(String j_name, String j_value);
public static native void nativeSetenv(String name, String value);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required given this is already defined in the parent class SDLActivity? I'm not 100% brushed up on my java knowledge but this looks like it might be redundant to me

Copy link

@ghost ghost Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right nevermind this is in a non-SDL2 bootstrap, I missed that for a second. all fine 👍

public static native int nativeInit(Object arguments);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
String entry_point = getEntryPoint(app_root_dir);

Log.v(TAG, "Setting env vars for start.c and Python to use");
PythonActivity.nativeSetEnv("ANDROID_ENTRYPOINT", entry_point);
PythonActivity.nativeSetEnv("ANDROID_ARGUMENT", app_root_dir);
PythonActivity.nativeSetEnv("ANDROID_APP_PATH", app_root_dir);
PythonActivity.nativeSetEnv("ANDROID_PRIVATE", mFilesDirectory);
PythonActivity.nativeSetEnv("ANDROID_UNPACK", app_root_dir);
PythonActivity.nativeSetEnv("PYTHONHOME", app_root_dir);
PythonActivity.nativeSetEnv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
PythonActivity.nativeSetEnv("PYTHONOPTIMIZE", "2");
PythonActivity.nativeSetenv("ANDROID_ENTRYPOINT", entry_point);
PythonActivity.nativeSetenv("ANDROID_ARGUMENT", app_root_dir);
PythonActivity.nativeSetenv("ANDROID_APP_PATH", app_root_dir);
PythonActivity.nativeSetenv("ANDROID_PRIVATE", mFilesDirectory);
PythonActivity.nativeSetenv("ANDROID_UNPACK", app_root_dir);
PythonActivity.nativeSetenv("PYTHONHOME", app_root_dir);
PythonActivity.nativeSetenv("PYTHONPATH", app_root_dir + ":" + app_root_dir + "/lib");
PythonActivity.nativeSetenv("PYTHONOPTIMIZE", "2");

try {
Log.v(TAG, "Access to our meta-data...");
Expand Down Expand Up @@ -461,7 +461,7 @@ public static void stop_service() {
}


public static native void nativeSetEnv(String j_name, String j_value);
public static native void nativeSetenv(String name, String value);
public static native int nativeInit(Object arguments);

}
Expand Down
2 changes: 0 additions & 2 deletions pythonforandroid/recipes/sdl2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class LibSDL2Recipe(BootstrapNDKRecipe):
depends = ['sdl2_image', 'sdl2_mixer', 'sdl2_ttf']
conflicts = ['sdl', 'pygame', 'pygame_bootstrap_components']

patches = ['add_nativeSetEnv.patch']

def get_recipe_env(self, arch=None, with_flags_in_cc=True, with_python=True):
env = super(LibSDL2Recipe, self).get_recipe_env(
arch=arch, with_flags_in_cc=with_flags_in_cc, with_python=with_python)
Expand Down
22 changes: 0 additions & 22 deletions pythonforandroid/recipes/sdl2/add_nativeSetEnv.patch

This file was deleted.