Update PythonUtil loadLibraries. Remove m abi flag from python3.9 lib.

This commit is contained in:
Akinwale Ariwodola 2021-08-20 21:31:14 +01:00
parent bb9b96350c
commit 60d9bf07bd
3 changed files with 42 additions and 38 deletions

View file

@ -76,7 +76,7 @@ public class PythonActivity extends SDLActivity {
public void loadLibraries() {
String app_root = new String(getAppRoot());
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) {

View file

@ -119,7 +119,7 @@ public class PythonService extends Service implements Runnable {
public void run(){
String app_root = getFilesDir().getAbsolutePath() + "/app";
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;
nativeStart(
androidPrivate, androidArgument,

View file

@ -1,35 +1,48 @@
package org.kivy.android;
import java.io.File;
import java.util.ArrayList;
import java.util.regex.Pattern;
import android.util.Log;
public class PythonUtil {
private static final String TAG = "PythonUtil";
private static final String TAG = "pythonutil";
protected static String[] getLibraries() {
return new String[] {
"SDL2",
"SDL2_image",
"SDL2_mixer",
"SDL2_ttf",
"python2.7",
"python3.5m",
"python3.6m",
"python3.7m",
"python3.9m",
"main"
};
protected static void addLibraryIfExists(ArrayList<String> libsList, String pattern, File libsDir) {
// pattern should be the name of the lib file, without the
// preceding "lib" or suffix ".so", for instance "ssl.*" will
// match files of the form "libssl.*.so".
File [] files = libsDir.listFiles();
pattern = "lib" + pattern + "\\.so";
Pattern p = Pattern.compile(pattern);
for (int i = 0; i < files.length; ++i) {
File file = files[i];
String name = file.getName();
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));
}
}
}
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;
}
public static void loadLibraries(File filesDir) {
String filesDirPath = filesDir.getAbsolutePath();
public static void loadLibraries(File filesDir, File libsDir) {
boolean foundPython = false;
for (String lib : getLibraries()) {
try {
for (String lib : getLibraries(libsDir)) {
Log.v(TAG, "Loading library: " + lib);
try {
System.loadLibrary(lib);
if (lib.startsWith("python")) {
foundPython = true;
@ -38,27 +51,18 @@ public class PythonUtil {
// If this is the last possible libpython
// load, and it has failed, give a more
// general error
Log.v(TAG, "Library loading error: " + e.getMessage());
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;
} else {
Log.v(TAG, "An UnsatisfiedLinkError occurred loading " + lib);
throw e;
}
continue;
}
}
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!");
}
}