Update PythonUtil loadLibraries. Remove m abi flag from python3.9 lib.
This commit is contained in:
parent
bb9b96350c
commit
60d9bf07bd
3 changed files with 42 additions and 38 deletions
|
@ -76,7 +76,7 @@ public class PythonActivity extends SDLActivity {
|
||||||
public void loadLibraries() {
|
public void loadLibraries() {
|
||||||
String app_root = new String(getAppRoot());
|
String app_root = new String(getAppRoot());
|
||||||
File app_root_file = new File(app_root);
|
File app_root_file = new File(app_root);
|
||||||
PythonUtil.loadLibraries(app_root_file);
|
PythonUtil.loadLibraries(app_root_file, new File(getApplicationInfo().nativeLibraryDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recursiveDelete(File f) {
|
public void recursiveDelete(File f) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class PythonService extends Service implements Runnable {
|
||||||
public void run(){
|
public void run(){
|
||||||
String app_root = getFilesDir().getAbsolutePath() + "/app";
|
String app_root = getFilesDir().getAbsolutePath() + "/app";
|
||||||
File app_root_file = new File(app_root);
|
File app_root_file = new File(app_root);
|
||||||
PythonUtil.loadLibraries(app_root_file);
|
PythonUtil.loadLibraries(app_root_file, new File(getApplicationInfo().nativeLibraryDir));
|
||||||
this.mService = this;
|
this.mService = this;
|
||||||
nativeStart(
|
nativeStart(
|
||||||
androidPrivate, androidArgument,
|
androidPrivate, androidArgument,
|
||||||
|
|
|
@ -1,34 +1,47 @@
|
||||||
package org.kivy.android;
|
package org.kivy.android;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
|
||||||
public class PythonUtil {
|
public class PythonUtil {
|
||||||
private static final String TAG = "PythonUtil";
|
private static final String TAG = "pythonutil";
|
||||||
|
|
||||||
protected static String[] getLibraries() {
|
protected static void addLibraryIfExists(ArrayList<String> libsList, String pattern, File libsDir) {
|
||||||
return new String[] {
|
// pattern should be the name of the lib file, without the
|
||||||
"SDL2",
|
// preceding "lib" or suffix ".so", for instance "ssl.*" will
|
||||||
"SDL2_image",
|
// match files of the form "libssl.*.so".
|
||||||
"SDL2_mixer",
|
File [] files = libsDir.listFiles();
|
||||||
"SDL2_ttf",
|
|
||||||
"python2.7",
|
pattern = "lib" + pattern + "\\.so";
|
||||||
"python3.5m",
|
Pattern p = Pattern.compile(pattern);
|
||||||
"python3.6m",
|
for (int i = 0; i < files.length; ++i) {
|
||||||
"python3.7m",
|
File file = files[i];
|
||||||
"python3.9m",
|
String name = file.getName();
|
||||||
"main"
|
Log.v(TAG, "Checking pattern " + pattern + " against " + name);
|
||||||
};
|
if (p.matcher(name).matches()) {
|
||||||
|
Log.v(TAG, "Pattern " + pattern + " matched file " + name);
|
||||||
|
libsList.add(name.substring(3, name.length() - 3));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadLibraries(File filesDir) {
|
protected static ArrayList<String> getLibraries(File libsDir) {
|
||||||
|
ArrayList<String> libsList = new ArrayList<String>();
|
||||||
|
libsList.add("python3.7m");
|
||||||
|
libsList.add("python3.8");
|
||||||
|
libsList.add("python3.9");
|
||||||
|
libsList.add("main");
|
||||||
|
return libsList;
|
||||||
|
}
|
||||||
|
|
||||||
String filesDirPath = filesDir.getAbsolutePath();
|
public static void loadLibraries(File filesDir, File libsDir) {
|
||||||
boolean foundPython = false;
|
boolean foundPython = false;
|
||||||
|
|
||||||
for (String lib : getLibraries()) {
|
for (String lib : getLibraries(libsDir)) {
|
||||||
|
Log.v(TAG, "Loading library: " + lib);
|
||||||
try {
|
try {
|
||||||
System.loadLibrary(lib);
|
System.loadLibrary(lib);
|
||||||
if (lib.startsWith("python")) {
|
if (lib.startsWith("python")) {
|
||||||
|
@ -38,25 +51,16 @@ public class PythonUtil {
|
||||||
// If this is the last possible libpython
|
// If this is the last possible libpython
|
||||||
// load, and it has failed, give a more
|
// load, and it has failed, give a more
|
||||||
// general error
|
// general error
|
||||||
|
Log.v(TAG, "Library loading error: " + e.getMessage());
|
||||||
if (lib.startsWith("python3.9") && !foundPython) {
|
if (lib.startsWith("python3.9") && !foundPython) {
|
||||||
throw new java.lang.RuntimeException("Could not load any libpythonXXX.so");
|
throw new RuntimeException("Could not load any libpythonXXX.so");
|
||||||
}
|
} else if (lib.startsWith("python")) {
|
||||||
continue;
|
continue;
|
||||||
|
} else {
|
||||||
|
Log.v(TAG, "An UnsatisfiedLinkError occurred loading " + lib);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
System.load(filesDirPath + "/lib/python2.7/lib-dynload/_io.so");
|
|
||||||
System.load(filesDirPath + "/lib/python2.7/lib-dynload/unicodedata.so");
|
|
||||||
} catch(UnsatisfiedLinkError e) {
|
|
||||||
Log.v(TAG, "Failed to load _io.so or unicodedata.so...but that's okay.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// System.loadLibrary("ctypes");
|
|
||||||
System.load(filesDirPath + "/lib/python2.7/lib-dynload/_ctypes.so");
|
|
||||||
} catch(UnsatisfiedLinkError e) {
|
|
||||||
Log.v(TAG, "Unsatisfied linker when loading ctypes");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.v(TAG, "Loaded everything!");
|
Log.v(TAG, "Loaded everything!");
|
||||||
|
|
Loading…
Reference in a new issue